al_papi 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +74 -74
- data/lib/al_papi/web_insight.rb +65 -0
- data/lib/al_papi.rb +2 -0
- metadata +19 -7
data/README.md
CHANGED
@@ -7,111 +7,111 @@ A wrapper around the Partner API calls. Allows post, priority post and get calls
|
|
7
7
|
|
8
8
|
## Install
|
9
9
|
|
10
|
-
|
10
|
+
gem install 'al_papi'
|
11
11
|
|
12
12
|
## Usage
|
13
|
-
|
13
|
+
|
14
14
|
Make a request object using your api key:
|
15
15
|
|
16
|
-
|
16
|
+
require 'al_papi'
|
17
17
|
|
18
|
-
|
18
|
+
req = AlPapi::Request.new(api_key: 'yR43BtBDjadfavMy6a6aK0')
|
19
19
|
|
20
20
|
### POST
|
21
|
-
|
21
|
+
|
22
22
|
Post your keyword-engine-locale combination to the API:
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
res = req.post keyword: "Centaur Love'n", engine: 'google', locale: 'en-us'
|
25
|
+
|
26
|
+
if res.success?
|
27
|
+
p 'Centaur High Hoof'
|
28
|
+
else
|
29
|
+
p 'PAPI Fail'
|
30
|
+
end
|
31
31
|
|
32
32
|
### Priority POST
|
33
|
-
|
33
|
+
|
34
34
|
Post your keyword to the priority queue if you need results in a more timely manner:
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
res = req.priority_post keyword: "Mad Scientist", engine: 'bing', locale: 'en-ca'
|
37
|
+
|
38
|
+
if res.success?
|
39
|
+
p 'Canadian Bing Scientist Time'
|
40
|
+
else
|
41
|
+
p 'PAPI Fail'
|
42
|
+
end
|
43
43
|
|
44
44
|
### GET
|
45
45
|
|
46
46
|
When you are ready to get your results you can do a GET request for your keyword-engine-locale combo:
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
|
48
|
+
res = req.get keyword: "Mad Scientist", engine: 'bing', locale: 'en-ca'
|
49
|
+
|
50
|
+
if res.success?
|
51
|
+
p 'Canadian Bing Scientist Time'
|
52
|
+
res.body # Hash of your results for that keyword-engine-locale
|
53
|
+
else
|
54
|
+
p 'PAPI Fail'
|
55
|
+
end
|
56
56
|
|
57
57
|
### Response
|
58
58
|
|
59
59
|
When making an API request a response object is returned with any errors, http response code and http reponse body.
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
61
|
+
res = req.get keyword: "Mad Scientist", engine: 'bing', locale: 'en-ca'
|
62
|
+
|
63
|
+
# Errors:
|
64
|
+
# Returns an array of error objects.
|
65
|
+
res.errors
|
66
|
+
|
67
|
+
if res.errors.present?
|
68
|
+
res.errors.each do |error|
|
69
|
+
p error.code # http repsonse code
|
70
|
+
p error.message # error message
|
71
|
+
p error.params # params of request
|
72
|
+
p error.path # path of request
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Success:
|
77
|
+
# Returns true or false if request was successful or not.
|
78
|
+
res.success?
|
79
|
+
|
80
|
+
# Body:
|
81
|
+
# Returns body of response.
|
82
|
+
# On GET requests the body will be a hash of your results if successful.
|
83
|
+
res.body
|
84
|
+
|
85
|
+
# Code:
|
86
|
+
# Returns http response code.
|
87
|
+
# 204: On GET requests when no data is available yet
|
88
|
+
# 200: Successful
|
89
|
+
# 401: Invalid api key
|
90
|
+
# 500: Server Error
|
91
|
+
res.code
|
92
|
+
|
93
|
+
# Over Limit:
|
94
|
+
# Returns true or false if over hourly limit
|
95
|
+
res.over_limit?
|
96
|
+
|
97
|
+
# Suspended:
|
98
|
+
# Returns true or false if your account has been suspended
|
99
|
+
res.suspended?
|
100
|
+
|
101
101
|
### Engines
|
102
102
|
|
103
103
|
Supported engines are Google, Yahoo and Bing. To get a list of supported engines run the following:
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
AlPapi::Engines.all
|
106
|
+
|
107
107
|
### Locales
|
108
108
|
|
109
109
|
Supported locales differ by the engine being used. In order to make sure you are using a supported locale
|
110
110
|
for the engine you are posting a keyword to there is a locales class to help you:
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
AlPapi::Locales.supported # returns an array of locales for the default engine Google
|
113
|
+
AlPapi::Locales.supported 'bing' # for other engines pass in the engine name
|
114
|
+
AlPapi::Locales.supported 'yahoo'
|
115
115
|
|
116
116
|
## License
|
117
117
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module AlPapi
|
2
|
+
|
3
|
+
class WebInsight
|
4
|
+
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
##
|
8
|
+
#
|
9
|
+
# [config] * Hash { auth_key: 'your_auth_token' }
|
10
|
+
# * OR AlPapi::Config
|
11
|
+
|
12
|
+
def initialize(config)
|
13
|
+
@config = config.is_a?(AlPapi::Config) ? config : Config.new(config)
|
14
|
+
@success, @errors = false, []
|
15
|
+
end
|
16
|
+
|
17
|
+
def http # @private
|
18
|
+
Http.new(@config)
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# == Params
|
23
|
+
#
|
24
|
+
# URL for the page you want insight into and the callback url you have implemented to know
|
25
|
+
# when results are ready to get.
|
26
|
+
#
|
27
|
+
# [url] <b>Required</b> -
|
28
|
+
# The web page you want to gain insight on.
|
29
|
+
# [callback] <em>Required</em> -
|
30
|
+
# Default is set on your account through the website.
|
31
|
+
# Set specific callbacks here for each request. Callback a url that
|
32
|
+
# is sent a POST when results are returned.
|
33
|
+
|
34
|
+
def post(params = {}, priority = false)
|
35
|
+
check_params Hashie::Mash.new(params), *%w[url callback]
|
36
|
+
http.post '/web/insight', params
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# == Params
|
41
|
+
#
|
42
|
+
# Parameters should be the same url as what was posted to the Partner API and the
|
43
|
+
# date_created and time_created values passed back to you via the callback posted.
|
44
|
+
#
|
45
|
+
# [url] <b>Required</b> -
|
46
|
+
# The URL originally posted to Partner API
|
47
|
+
# [date_created] <em>Required</em> -
|
48
|
+
# The date_created that was returned in the callback.
|
49
|
+
# [time_created] <em>Required</em> -
|
50
|
+
# The time_created that was returned in the callback.
|
51
|
+
|
52
|
+
def get(params = {})
|
53
|
+
check_params Hashie::Mash.new(params), *%w[date_created time_created]
|
54
|
+
http.get '/web/insight', params
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_params(params, *param)
|
58
|
+
param.each do |p|
|
59
|
+
raise "#{p} parameter is required." if params[p].nil? || params[p.to_s].empty?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/al_papi.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest-client'
|
3
3
|
require 'net/http'
|
4
|
+
require 'hashie'
|
4
5
|
|
5
6
|
module AlPapi
|
6
7
|
|
@@ -13,3 +14,4 @@ require File.dirname(__FILE__) + '/al_papi/request_error'
|
|
13
14
|
require File.dirname(__FILE__) + '/al_papi/response'
|
14
15
|
require File.dirname(__FILE__) + '/al_papi/locales'
|
15
16
|
require File.dirname(__FILE__) + '/al_papi/engines'
|
17
|
+
require File.dirname(__FILE__) + '/al_papi/web_insight'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: al_papi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: &
|
16
|
+
requirement: &70322796432540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.6.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70322796432540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: hashie
|
27
|
+
requirement: &70322796431940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: '2.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70322796431940
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70322796431440 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70322796431440
|
36
47
|
description: Wraps AuthorityLabs Partner API calls in a gem.
|
37
48
|
email: ''
|
38
49
|
executables: []
|
@@ -48,6 +59,7 @@ files:
|
|
48
59
|
- lib/al_papi/request_error.rb
|
49
60
|
- lib/al_papi/request.rb
|
50
61
|
- lib/al_papi/response.rb
|
62
|
+
- lib/al_papi/web_insight.rb
|
51
63
|
- README.md
|
52
64
|
homepage: http://github.com/mtchavez/al_papi
|
53
65
|
licenses: []
|
@@ -70,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
82
|
version: '0'
|
71
83
|
requirements: []
|
72
84
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.17
|
74
86
|
signing_key:
|
75
87
|
specification_version: 3
|
76
88
|
summary: AuthorityLabs Partner API Wrapper
|