Permalink
Browse files

v0.0.15 Web Insight API Call Added

Removed rspec as dependency and is only dev dependency now.
Require hashie for indifferent access to hashes.
Added Web Insight class to make get/post calls to PAPI.
Bumped gem version to 0.0.15
  • Loading branch information...
Chavez
Chavez committed Jun 14, 2012
1 parent 01b9876 commit 5cebfe44ce8e01bd3392aa10ff467a8ecdec883e
Showing with 91 additions and 3 deletions.
  1. BIN al_papi-0.0.15.gem
  2. +4 −3 al_papi.gemspec
  3. +2 −0 lib/al_papi.rb
  4. +65 −0 lib/al_papi/web_insight.rb
  5. +20 −0 spec/web_insight_spec.rb
View
Binary file not shown.
View
@@ -1,17 +1,18 @@
Gem::Specification.new do |s|
s.name = 'al_papi'
- s.version = '0.0.14'
+ s.version = '0.0.15'
s.date = '2012-01-05'
s.summary = "AuthorityLabs Partner API Wrapper"
s.description = "Wraps AuthorityLabs Partner API calls in a gem."
s.authors = ['Chavez']
s.email = ''
- s.files = ['lib/al_papi.rb', 'lib/al_papi/config.rb', 'lib/al_papi/engines.rb', 'lib/al_papi/http.rb', 'lib/al_papi/locales.rb', 'lib/al_papi/request_error.rb', 'lib/al_papi/request.rb', 'lib/al_papi/response.rb']
+ s.files = ['lib/al_papi.rb', 'lib/al_papi/config.rb', 'lib/al_papi/engines.rb', 'lib/al_papi/http.rb', 'lib/al_papi/locales.rb', 'lib/al_papi/request_error.rb', 'lib/al_papi/request.rb', 'lib/al_papi/response.rb', 'lib/al_papi/web_insight.rb']
s.require_paths = ['lib']
s.homepage = 'http://github.com/mtchavez/al_papi'
s.rdoc_options = ['--charset=UTF-8 --main=README.md']
s.extra_rdoc_files = ['README.md']
s.add_dependency(%q<rest-client>, ['>= 1.6.7'])
- s.add_dependency(%q<rspec>, ['>= 2.0'])
+ s.add_dependency(%q<hashie>, ['>= 2.0'])
+ s.add_development_dependency(%q<rspec>, ['>= 2.0'])
end
View
@@ -1,6 +1,7 @@
require 'json'
require 'rest-client'
require 'net/http'
+require 'hashie'
module AlPapi
@@ -13,3 +14,4 @@ module AlPapi
require File.dirname(__FILE__) + '/al_papi/response'
require File.dirname(__FILE__) + '/al_papi/locales'
require File.dirname(__FILE__) + '/al_papi/engines'
+require File.dirname(__FILE__) + '/al_papi/web_insight'
View
@@ -0,0 +1,65 @@
+module AlPapi
+
+ class WebInsight
+
+ attr_reader :config
+
+ ##
+ #
+ # [config] * Hash { auth_key: 'your_auth_token' }
+ # * OR AlPapi::Config
+
+ def initialize(config)
+ @config = config.is_a?(AlPapi::Config) ? config : Config.new(config)
+ @success, @errors = false, []
+ end
+
+ def http # @private
+ Http.new(@config)
+ end
+
+ ##
+ # == Params
+ #
+ # URL for the page you want insight into and the callback url you have implemented to know
+ # when results are ready to get.
+ #
+ # [url] <b>Required</b> -
+ # The web page you want to gain insight on.
+ # [callback] <em>Required</em> -
+ # Default is set on your account through the website.
+ # Set specific callbacks here for each request. Callback a url that
+ # is sent a POST when results are returned.
+
+ def post(params = {}, priority = false)
+ check_params Hashie::Mash.new(params), *%w[url callback]
+ http.post '/web/insight', params
+ end
+
+ ##
+ # == Params
+ #
+ # Parameters should be the same url as what was posted to the Partner API and the
+ # date_created and time_created values passed back to you via the callback posted.
+ #
+ # [url] <b>Required</b> -
+ # The URL originally posted to Partner API
+ # [date_created] <em>Required</em> -
+ # The date_created that was returned in the callback.
+ # [time_created] <em>Required</em> -
+ # The time_created that was returned in the callback.
+
+ def get(params = {})
+ check_params Hashie::Mash.new(params), *%w[date_created time_created]
+ http.get '/web/insight', params
+ end
+
+ def check_params(params, *param)
+ param.each do |p|
+ raise "#{p} parameter is required." if params[p].nil? || params[p.to_s].empty?
+ end
+ end
+
+ end
+
+end
View
@@ -0,0 +1,20 @@
+require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
+
+describe AlPapi::WebInsight do
+
+ describe 'initialize' do
+
+ it 'takes a config object' do
+ config = AlPapi::Config.new(api_key: TEST_KEY)
+ req = AlPapi::WebInsight.new(config)
+ req.config.should be_an_instance_of(AlPapi::Config)
+ end
+
+ it 'takes a config hash' do
+ req = AlPapi::WebInsight.new(api_key: TEST_KEY)
+ req.config.should be_an_instance_of(AlPapi::Config)
+ end
+
+ end
+
+end

0 comments on commit 5cebfe4

Please sign in to comment.