diff --git a/.gitignore b/.gitignore index 4e2e872..f50d1e1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -39,7 +42,7 @@ pkg #.\#* # For vim: -#*.swp +*.swp # For redcar: #.redcar @@ -50,4 +53,4 @@ pkg .idea/ *.lock -*.gem \ No newline at end of file +*.gem diff --git a/README.md b/README.md index 7b76637..7194878 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/lib/fullcontact/client.rb b/lib/fullcontact/client.rb index ce88853..af826b7 100644 --- a/lib/fullcontact/client.rb +++ b/lib/fullcontact/client.rb @@ -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 diff --git a/lib/fullcontact/client/stats.rb b/lib/fullcontact/client/stats.rb new file mode 100644 index 0000000..aad25fa --- /dev/null +++ b/lib/fullcontact/client/stats.rb @@ -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 diff --git a/lib/fullcontact/version.rb b/lib/fullcontact/version.rb index 491d97f..47c239f 100644 --- a/lib/fullcontact/version.rb +++ b/lib/fullcontact/version.rb @@ -1,3 +1,3 @@ module FullContact - VERSION = '0.18.0' + VERSION = '0.19.0' end diff --git a/spec/fixtures/stats.json b/spec/fixtures/stats.json new file mode 100644 index 0000000..d2be7e3 --- /dev/null +++ b/spec/fixtures/stats.json @@ -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 + } + ] +} diff --git a/spec/ruby_fullcontact/client/stats_spec.rb b/spec/ruby_fullcontact/client/stats_spec.rb new file mode 100644 index 0000000..2441ae3 --- /dev/null +++ b/spec/ruby_fullcontact/client/stats_spec.rb @@ -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