Skip to content
This repository was archived by the owner on Aug 20, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ doc
# bundler
.bundle

# rmv
.rvmrc

# jeweler generated
pkg

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
Expand All @@ -39,7 +42,7 @@ pkg
#.\#*

# For vim:
#*.swp
*.swp

# For redcar:
#.redcar
Expand All @@ -50,4 +53,4 @@ pkg
.idea/
*.lock

*.gem
*.gem
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ A Ruby wrapper for the [FullContact API](http://www.fullcontact.com/)

Changes
-------
- 0.19.0
- Add Account Stats API support for Full Contact
- 0.18.0
- Add ability to query Company API by company name
- Fix XML bug in Company API module
Expand Down Expand Up @@ -121,6 +123,15 @@ You can also query the Company API
=> "FullContact Inc."
```

You can also query the Account Stats API
```ruby
# Get information about the current month
stats1 = FullContact.stats

# Get information about a specific month
stats2 = FullContact.stats(period: '2012-08')
```

The Company API also supports searching by company name.
Please see [our API documentation](https://www.fullcontact.com/developer/docs/company/#lookup-by-company-name) for more details.
```ruby
Expand Down
2 changes: 2 additions & 0 deletions lib/fullcontact/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class Client < API
# Client-namespaced.
require 'fullcontact/client/person'
require 'fullcontact/client/company'
require 'fullcontact/client/stats'

alias :api_endpoint :endpoint

include FullContact::Client::Person
include FullContact::Client::Company
include FullContact::Client::Stats
end
end
12 changes: 12 additions & 0 deletions lib/fullcontact/client/stats.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module FullContact
class Client
module Stats
# Returns extended information of your API account usage for the current month or a previous month
#
def stats(options={}, faraday_options={})
response = get('stats', options, false, faraday_options)
format.to_s.downcase == 'xml' ? response['response'] : response
end
end
end
end
2 changes: 1 addition & 1 deletion lib/fullcontact/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FullContact
VERSION = '0.18.0'
VERSION = '0.19.0'
end
50 changes: 50 additions & 0 deletions spec/fixtures/stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"status": 200,
"periodStart": "2012-11-01T00:00:00 -0600",
"periodEnd": "2012-11-30T23:59:59 -0700",
"plan": "Fictitious $99.00/mo with $0.03 overage",
"planBasePrice": 99,
"planOveragePrice": 0.03,
"applicationId": "xxxxxxxxxxxxx",
"metrics":
[
{
"metricName": "Success - Basic (\"200\")",
"metricId": "200",
"planLevel": 10000,
"usage": 170,
"remaining": 9830,
"overage": 0
},
{
"metricName": "Success - No Charge (\"200\")",
"metricId": "200_free",
"usage": 0
},
{
"metricName": "Bad Request (\"400\")",
"metricId": "400",
"usage": 0
},
{
"metricName": "Success - Enhanced (\"200\")",
"metricId": "enhanced_200",
"usage": 0
},
{
"metricName": "Success - Card Reader (\"202\")",
"metricId": "202_CardShark",
"usage": 0
},
{
"metricName": "Queued (\"202\")",
"metricId": "202",
"usage": 9
},
{
"metricName": "Not Found (\"404\")",
"metricId": "404",
"usage": 36
}
]
}
35 changes: 35 additions & 0 deletions spec/ruby_fullcontact/client/stats_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'helper'

describe FullContact::Client::Stats do
FullContact::Configuration::VALID_FORMATS.each do |format|
context ".new(:format => '#{format}')" do
before do
@client = FullContact::Client.new(:format => format, :api_key => 'api_key')
end

end
end

context "when parsing a response" do

before do
FullContact.configure do |config|
config.api_key = "api_key"
end

stub_get("stats.json").
with(:query => {:apiKey => "api_key"}).
to_return(:body => fixture("stats.json"), :headers => {:content_type => "application/json; charset=utf-8"})

stub_get("company/lookup.json").
with(:query => {:apiKey => "api_key", :period => "2012-08"}).
to_return(:body => fixture("stats.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end

it 'should rubyize keys' do
expect(FullContact.stats.status).to(eq(200))

expect(FullContact.stats.planBasePrice).to(eq(99))
end
end
end