al_papi 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f94f272af2e8d0822dc70cd7d1b581b1bd06634d
4
- data.tar.gz: c54796aa7be95b01098df4debd8b717a10caa84a
3
+ metadata.gz: 7a47ff1544d5b8ec96e73041252b8a2b78d9eab7
4
+ data.tar.gz: 548aedb6dbe56473a9ba120c7ace7725552836c1
5
5
  SHA512:
6
- metadata.gz: 7856c8183a2cbc513dba37e98196eda31f845a54bd7311d1b6945616201b565eeee1ef6f6385deadf784ec926333fbc94b11a300019bbb4a1b00d6eed004fd2d
7
- data.tar.gz: a04e5850d2e157cbd3abad145417032aa6a538ba6cdd9394ce5d9ee062d68f42983e502285751dfbd1f9450605fed977b19c4f6d83c2c6889d34ae06188ae906
6
+ metadata.gz: ad6c92cac8048b42d9df3c3680a72042dd593eff8aa9356a4178d3482423aaff00eb2c028d816a0f103a8e445b392232d1a4f8b98eb2e9fd2f6375280a157708
7
+ data.tar.gz: 2553763ba2ee05ac78e400b3486942e1a9711962ce1b22e82eda00d4c23599a1ab000423ee0b4da101a83ff31ff57342b76a918ac8d9c3969e1f837275b452a2
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
- AuthorityLabs Partner API Gem
2
- =============================
1
+ # AuthorityLabs Partner API Gem
3
2
 
4
- A wrapper around the Partner API calls. Allows post, priority post and get calls.
3
+ [![Latest Version](http://img.shields.io/github/release/mtchavez/skiplist.svg?style=flat-square)](https://github.com/mtchavez/al_papi/releases)
4
+ [![Build Status](https://secure.travis-ci.org/mtchavez/al_papi.png)](http://travis-ci.org/mtchavez/al_papi?branch=master)
5
+ [![Coverage Status](https://coveralls.io/repos/mtchavez/al_papi/badge.png?branch=update%2Fdependencies)](https://coveralls.io/r/mtchavez/al_papi?branch=update%2Fdependencies)
6
+ [![Code Climate](https://codeclimate.com/github/mtchavez/al_papi.png)](https://codeclimate.com/github/mtchavez/al_papi)
5
7
 
6
- * Github: http://github.com/mtchavez/al_papi
7
- * [![Build Status](https://secure.travis-ci.org/mtchavez/al_papi.png)](http://travis-ci.org/mtchavez/al_papi?branch=master)
8
- * [![Code Climate](https://codeclimate.com/github/mtchavez/al_papi.png)](https://codeclimate.com/github/mtchavez/al_papi)
8
+ A wrapper around the Partner API calls. Allows post, priority post and get calls.
9
9
 
10
10
  ## Install
11
11
 
12
- gem install 'al_papi'
12
+ ```ruby
13
+ gem install 'al_papi'
14
+ ```
13
15
 
14
16
  ## Configuration
15
17
 
@@ -35,7 +37,7 @@ res = AlPapi::Account.info '1'
35
37
  res.body
36
38
 
37
39
  # You can use the parsed_body method for convenience to access data
38
- account_info = @res.parsed_body
40
+ account_info = res.parsed_body
39
41
  account_info.user.current_balance # 500.00
40
42
  account_info.queue.bing_time # 15
41
43
  account_info.messages.system # ['The system is back online!']
@@ -249,9 +251,3 @@ Example response
249
251
  engine: google
250
252
  }
251
253
  ```
252
-
253
- ## License
254
-
255
- Written by Chavez
256
-
257
- Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
@@ -13,9 +13,12 @@ require File.dirname(__FILE__) + '/al_papi/request_error'
13
13
  require File.dirname(__FILE__) + '/al_papi/response'
14
14
  require File.dirname(__FILE__) + '/al_papi/web_insight'
15
15
 
16
- module AlPapi
16
+ def ruby_19?
17
+ RUBY_VERSION == '1.9.3'
18
+ end
17
19
 
18
- extend self
20
+ module AlPapi
21
+ module_function unless ruby_19?
19
22
 
20
23
  ##
21
24
  # @example Configure takes block to set API key to be used in API calls.
@@ -26,6 +29,7 @@ module AlPapi
26
29
  def configure
27
30
  yield config
28
31
  end
32
+ module_function :configure if ruby_19?
29
33
 
30
34
  #
31
35
  # @return [AlPapi::Config]
@@ -33,9 +37,10 @@ module AlPapi
33
37
  def config
34
38
  @config ||= Config.new
35
39
  end
40
+ module_function :config if ruby_19?
36
41
 
37
42
  def http # @private
38
43
  Http.new(config)
39
44
  end
40
-
45
+ module_function :http if ruby_19?
41
46
  end
@@ -1,7 +1,5 @@
1
1
  module AlPapi
2
-
3
2
  class Account
4
-
5
3
  ##
6
4
  # Details for your account including hourly POST/GET limits, current queue times and current balance.
7
5
  # Also includes any system messages posted about the API.
@@ -11,7 +9,5 @@ module AlPapi
11
9
  def self.info(account_id)
12
10
  AlPapi.http.get "/account/#{account_id}"
13
11
  end
14
-
15
12
  end
16
-
17
13
  end
@@ -1,17 +1,15 @@
1
1
  module AlPapi
2
-
3
2
  ##
4
3
  #
5
4
  # Config class used internally.
6
5
  # Configure API calls using AlPapi.configure
7
6
 
8
7
  class Config
9
-
10
8
  DEFAULT_HOST = 'http://api.authoritylabs.com'
11
9
  DEFAULT_PORT = 80 # @private
12
10
 
13
11
  attr_accessor :api_key
14
- attr_reader :host, :port # @private
12
+ attr_reader :host, :port # @private
15
13
 
16
14
  ##
17
15
  #
@@ -21,7 +19,5 @@ module AlPapi
21
19
  @host = DEFAULT_HOST
22
20
  @port = DEFAULT_PORT
23
21
  end
24
-
25
22
  end
26
-
27
23
  end
@@ -1,7 +1,5 @@
1
1
  module AlPapi
2
-
3
2
  class Engines
4
-
5
3
  ##
6
4
  # Supported engines for Partner API.
7
5
  #
@@ -10,7 +8,5 @@ module AlPapi
10
8
  def self.all
11
9
  %w[google bing yahoo]
12
10
  end
13
-
14
11
  end
15
-
16
12
  end
@@ -1,11 +1,10 @@
1
1
  module AlPapi
2
-
3
2
  class Http # @private
4
-
3
+ HANDLED_CODES = [200, 204, 401, 403]
5
4
  attr_accessor :errors, :response, :success, :config, :over_limit, :suspended
6
5
 
7
- def initialize(_config)
8
- @config, @errors, @success, @over_limit, @suspended = _config, [], false, false, false
6
+ def initialize(config)
7
+ @config, @errors, @success, @over_limit, @suspended = config, [], false, false, false
9
8
  end
10
9
 
11
10
  def get(path, params = {})
@@ -17,7 +16,7 @@ module AlPapi
17
16
  end
18
17
 
19
18
  def build_params(params = {})
20
- params.merge(:auth_token => @config.api_key, :format => 'json')
19
+ params.merge(auth_token: @config.api_key, format: 'json')
21
20
  end
22
21
 
23
22
  def request(http_verb, path, params = nil)
@@ -25,41 +24,50 @@ module AlPapi
25
24
  args = [http_verb, url]
26
25
  args << params if http_verb == 'post'
27
26
 
28
- RestClient.send(*args) do |res, req, raw_res|
29
- body = raw_res.body
30
- code = raw_res.code.to_i
27
+ RestClient.send(*args) do |res|
28
+ body = res.body
29
+ code = res.code.to_i
31
30
 
32
31
  self.response = body
33
32
  self.errors = []
34
33
 
35
- case code
36
- when 200
37
- begin
38
- JSON.parse body
39
- rescue JSON::ParserError
40
- self.response = body
41
- end
42
- self.success = true
43
- when 204
44
- self.errors << RequestError.new('No Content', code, path, params)
45
- when 401
46
- self.errors << RequestError.new('Invalid Auth Token Provided', code, path, params)
47
- when 403
48
- if body.match(/Account Suspended/i)
49
- self.suspended = true
50
- self.errors << RequestError.new('Account Suspended', code, path, params)
51
- elsif body.match(/Request Limit Exceeded/i)
52
- self.over_limit = true
53
- self.errors << RequestError.new('Request Limit Exceeded', code, path, params)
54
- end
34
+ if HANDLED_CODES.include?(code)
35
+ send "handle_#{code}", body, code, path, params
55
36
  else
56
- self.errors << RequestError.new(body, code, path, params)
37
+ errors << RequestError.new(body, code, path, params)
57
38
  end
58
39
 
59
40
  Response.new(self, code, path, params)
60
41
  end
61
42
  end
62
43
 
63
- end
44
+ def handle_200(body, _code, _path, _params)
45
+ # Check valid JSON body.
46
+ # API returns 'OK' in some cases where response has no
47
+ # meaningful body, which is invalid JSON, so let it be
48
+ # a successfull call
49
+ JSON.parse body unless body == 'OK'
50
+ self.success = true
51
+ rescue JSON::ParserError
52
+ self.response = body
53
+ end
54
+
55
+ def handle_204(_body, code, path, params)
56
+ errors << RequestError.new('No Content', code, path, params)
57
+ end
64
58
 
59
+ def handle_401(_body, code, path, params)
60
+ errors << RequestError.new('Invalid Auth Token Provided', code, path, params)
61
+ end
62
+
63
+ def handle_403(body, code, path, params)
64
+ if body.match(/Account Suspended/i)
65
+ self.suspended = true
66
+ errors << RequestError.new('Account Suspended', code, path, params)
67
+ elsif body.match(/Request Limit Exceeded/i)
68
+ self.over_limit = true
69
+ errors << RequestError.new('Request Limit Exceeded', code, path, params)
70
+ end
71
+ end
72
+ end
65
73
  end
@@ -1,7 +1,5 @@
1
1
  module AlPapi
2
-
3
2
  class Keyword
4
-
5
3
  ##
6
4
  #
7
5
  # POST a keyword/engine/locale combination to get SERP for.
@@ -9,18 +7,21 @@ module AlPapi
9
7
  # @param keyword [String] *Required* - The keyword you are ready to get results for.
10
8
  # @param engine [String] _Optional_ - Defaults to google
11
9
  # @param locale [String] _Optional_ - Defaults to en-us. See {AlPapi::Locales} for supported locales.
12
- # @param pages_from [String] _Optional_ - Defaults is false. Google specific parameter to get results from locale passed in when set to true.
13
- # @param callback [String] _Optional_ - Default is the callback you have set for your account. Set specific callbacks per request by using this paramerter. A POST is sent to this callback URL when results are returned.
10
+ # @param pages_from [String] _Optional_ - Defaults is false. Google specific parameter
11
+ # to get results from locale passed in when set to true.
12
+ # @param callback [String] _Optional_ - Default is the callback you have set for your account.
13
+ # Set specific callbacks per request by using this paramerter.
14
+ # A POST is sent to this callback URL when results are returned.
14
15
 
15
16
  def self.post(params = {}, priority = false)
16
17
  path = priority ? '/keywords/priority' : '/keywords'
17
18
  AlPapi.http.post path, params
18
19
  end
19
-
20
+
20
21
  ##
21
22
  #
22
23
  # See post method {AlPapi::Keyword.post} for required params
23
-
24
+
24
25
  def self.priority_post(params = {})
25
26
  post params, true
26
27
  end
@@ -39,7 +40,5 @@ module AlPapi
39
40
  def self.get(params = {})
40
41
  AlPapi.http.get '/keywords/get', params
41
42
  end
42
-
43
43
  end
44
-
45
44
  end
@@ -1,11 +1,10 @@
1
1
  module AlPapi
2
-
3
2
  class Locales
4
-
5
3
  ##
6
4
  #
7
5
  # Get supported locales for specified engine.
8
- # @param engine [String] Defaults to google. Returns Partner API supported locales for engine or not supported message.
6
+ # @param engine [String] Defaults to google. Returns Partner API supported
7
+ # locales for engine or not supported message.
9
8
 
10
9
  def self.supported(engine = 'google')
11
10
  AlPapi.http.get "/supported/#{engine}"
@@ -20,7 +19,5 @@ module AlPapi
20
19
  def self.description(engine = 'google', locale = 'en-us')
21
20
  AlPapi.http.get "/supported/#{engine}/#{locale.downcase}"
22
21
  end
23
-
24
22
  end
25
-
26
23
  end
@@ -1,13 +1,9 @@
1
1
  module AlPapi
2
-
3
2
  class RequestError
4
-
5
3
  attr_reader :message, :code, :path, :params
6
4
 
7
- def initialize(_message, _code, _path, _params) # @private
8
- @message, @code, @path, @params = _message, _code, _path, _params
5
+ def initialize(message, code, path, params) # @private
6
+ @message, @code, @path, @params = message, code, path, params
9
7
  end
10
-
11
8
  end
12
-
13
9
  end
@@ -1,7 +1,5 @@
1
1
  module AlPapi
2
-
3
2
  class Response
4
-
5
3
  attr_reader :success, :body, :errors, :code, :path, :params, :over_limit, :suspeneded
6
4
 
7
5
  ##
@@ -9,19 +7,19 @@ module AlPapi
9
7
  #
10
8
  # @private
11
9
 
12
- def initialize(http, _code, _path, _params) # @private
10
+ def initialize(http, code, path, params) # @private
13
11
  @success, @body, @errors = http.success, http.response, http.errors
14
12
  @over_limit, @suspended = http.over_limit, http.suspended
15
- @code, @path, @params = _code, _path, _params
13
+ @code, @path, @params = code, path, params
16
14
  end
17
-
15
+
18
16
  ##
19
17
  #
20
18
  # Convenience method to determine if request was successfull or not
21
19
  # @return [Boolean]
22
20
 
23
21
  def success?
24
- !!@success
22
+ @success ? true : false
25
23
  end
26
24
 
27
25
  ##
@@ -30,7 +28,7 @@ module AlPapi
30
28
  # @return [Boolean]
31
29
 
32
30
  def over_limit?
33
- !!@over_limit
31
+ @over_limit ? true : false
34
32
  end
35
33
 
36
34
  ##
@@ -39,7 +37,7 @@ module AlPapi
39
37
  # @return [Boolean]
40
38
 
41
39
  def suspended?
42
- !!@suspended
40
+ @suspended ? true : false
43
41
  end
44
42
 
45
43
  ##
@@ -48,10 +46,10 @@ module AlPapi
48
46
  # @return [Hashie::Mash]
49
47
 
50
48
  def parsed_body
51
- hash = JSON.parse(@body) rescue {}
49
+ hash = JSON.parse(@body)
52
50
  Hashie::Mash.new hash
51
+ rescue
52
+ {}
53
53
  end
54
-
55
54
  end
56
-
57
55
  end
@@ -1,7 +1,5 @@
1
1
  module AlPapi
2
-
3
2
  class WebInsight
4
-
5
3
  ENDPOINT = '/web/insight'
6
4
 
7
5
  ##
@@ -10,7 +8,10 @@ module AlPapi
10
8
  # when results are ready to get.
11
9
  #
12
10
  # @param url [String] *Required* - The web page you want to gain insight on.
13
- # @param callback [String] *Required* - Default is the callback you have set for your account. Set specific callbacks per request by using this paramerter. A POST is sent to this callback URL when results are returned.
11
+ # @param callback [String] *Required* - Default is the callback you have set for
12
+ # your account. Set specific callbacks per request
13
+ # by using this paramerter. A POST is sent to this
14
+ # callback URL when results are returned.
14
15
  # @raise [] When required parameter is not found.
15
16
 
16
17
  def self.post(params = {})
@@ -32,8 +33,6 @@ module AlPapi
32
33
  request 'get', params
33
34
  end
34
35
 
35
- private
36
-
37
36
  ##
38
37
  #
39
38
  # Check if required params exist
@@ -41,14 +40,12 @@ module AlPapi
41
40
 
42
41
  def self.check_params(params, *param)
43
42
  param.each do |p|
44
- raise "#{p} parameter is required." if params[p].nil? || params[p.to_s].empty?
43
+ fail "#{p} parameter is required." if params[p].nil? || params[p.to_s].empty?
45
44
  end
46
45
  end
47
46
 
48
47
  def self.request(method, params = {})
49
48
  AlPapi.http.send method, ENDPOINT, params
50
49
  end
51
-
52
50
  end
53
-
54
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: al_papi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chavez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -76,160 +76,160 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: 0.9.12
79
+ version: '0.10'
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.9.12.6
82
+ version: 0.10.1
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.9.12
89
+ version: '0.10'
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 0.9.12.6
92
+ version: 0.10.1
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rake
95
95
  requirement: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: 10.1.0
99
+ version: '10.4'
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 10.1.0
102
+ version: 10.4.0
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 10.1.0
109
+ version: '10.4'
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 10.1.0
112
+ version: 10.4.0
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: redcarpet
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: 3.1.0
119
+ version: '3.2'
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: 3.1.0
122
+ version: 3.2.1
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 3.1.0
129
+ version: '3.2'
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 3.1.0
132
+ version: 3.2.1
133
133
  - !ruby/object:Gem::Dependency
134
134
  name: rspec
135
135
  requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: 2.14.1
139
+ version: '3.1'
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
- version: 2.14.1
142
+ version: 3.1.0
143
143
  type: :development
144
144
  prerelease: false
145
145
  version_requirements: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - "~>"
148
148
  - !ruby/object:Gem::Version
149
- version: 2.14.1
149
+ version: '3.1'
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 2.14.1
152
+ version: 3.1.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.8.2
159
+ version: '0.9'
160
160
  - - ">="
161
161
  - !ruby/object:Gem::Version
162
- version: 0.8.2
162
+ version: 0.9.1
163
163
  type: :development
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
167
  - - "~>"
168
168
  - !ruby/object:Gem::Version
169
- version: 0.8.2
169
+ version: '0.9'
170
170
  - - ">="
171
171
  - !ruby/object:Gem::Version
172
- version: 0.8.2
172
+ version: 0.9.1
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: vcr
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 2.2.5
179
+ version: '2.9'
180
180
  - - ">="
181
181
  - !ruby/object:Gem::Version
182
- version: 2.2.5
182
+ version: 2.9.3
183
183
  type: :development
184
184
  prerelease: false
185
185
  version_requirements: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - "~>"
188
188
  - !ruby/object:Gem::Version
189
- version: 2.2.5
189
+ version: '2.9'
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
- version: 2.2.5
192
+ version: 2.9.3
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: webmock
195
195
  requirement: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: 1.8.11
199
+ version: '1.20'
200
200
  - - ">="
201
201
  - !ruby/object:Gem::Version
202
- version: 1.8.11
202
+ version: 1.20.4
203
203
  type: :development
204
204
  prerelease: false
205
205
  version_requirements: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - "~>"
208
208
  - !ruby/object:Gem::Version
209
- version: 1.8.11
209
+ version: '1.20'
210
210
  - - ">="
211
211
  - !ruby/object:Gem::Version
212
- version: 1.8.11
212
+ version: 1.20.4
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: yard
215
215
  requirement: !ruby/object:Gem::Requirement
216
216
  requirements:
217
217
  - - "~>"
218
218
  - !ruby/object:Gem::Version
219
- version: 0.8.7
219
+ version: '0.8'
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
- version: 0.8.7.4
222
+ version: 0.8.7.6
223
223
  type: :development
224
224
  prerelease: false
225
225
  version_requirements: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: 0.8.7
229
+ version: '0.8'
230
230
  - - ">="
231
231
  - !ruby/object:Gem::Version
232
- version: 0.8.7.4
232
+ version: 0.8.7.6
233
233
  description: Wraps AuthorityLabs Partner API calls in a gem.
234
234
  email: ''
235
235
  executables: []
@@ -273,4 +273,3 @@ signing_key:
273
273
  specification_version: 4
274
274
  summary: AuthorityLabs Partner API Wrapper
275
275
  test_files: []
276
- has_rdoc: