agent_cooper 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -10
- data/features/support/env.rb +4 -2
- data/lib/agent_cooper/config.rb +17 -0
- data/lib/agent_cooper/finder.rb +8 -12
- data/lib/agent_cooper/merchandiser.rb +10 -14
- data/lib/agent_cooper/request.rb +20 -37
- data/lib/agent_cooper/response.rb +25 -19
- data/lib/agent_cooper/shopper.rb +9 -13
- data/lib/agent_cooper/version.rb +1 -1
- data/lib/agent_cooper.rb +2 -1
- data/spec/agent_cooper/config_spec.rb +21 -0
- data/spec/agent_cooper/request_spec.rb +5 -11
- metadata +6 -3
data/README.md
CHANGED
@@ -11,11 +11,13 @@ Currently the following eBay APIs are supported:
|
|
11
11
|
Usage
|
12
12
|
-----
|
13
13
|
Set up.
|
14
|
-
|
15
|
-
AgentCooper::
|
14
|
+
|
15
|
+
AgentCooper::Config.set do |config|
|
16
|
+
config.app_id = "SOME_OBSCURE_APP_ID"
|
17
|
+
end
|
16
18
|
|
17
19
|
Initialize a request
|
18
|
-
|
20
|
+
|
19
21
|
request = AgentCooper::Finder.new
|
20
22
|
request = AgentCooper::Shopper.new
|
21
23
|
request = AgentCooper::Merchandiser.new
|
@@ -23,15 +25,22 @@ Initialize a request
|
|
23
25
|
Build request params.
|
24
26
|
|
25
27
|
request << {
|
26
|
-
'OPERATION-NAME' => '
|
27
|
-
'
|
28
|
+
'OPERATION-NAME' => 'getSearchKeywordsRecommendation',
|
29
|
+
'KEYWORDS' => 'arry potter'
|
28
30
|
}
|
29
31
|
|
30
32
|
Get a response.
|
31
33
|
|
32
34
|
response = request.get
|
33
35
|
|
34
|
-
|
36
|
+
Return a hash:
|
37
|
+
|
38
|
+
response.to_hash
|
39
|
+
|
40
|
+
returns: {'getSearchKeywordsRecommendationResponse' => {'xmnls' => 'http://www.ebay.com/marketplace/search/v1/services', 'ack' => 'Success', 'version' => '1.9.0', 'keywords' => 'harry potter'}}
|
41
|
+
|
42
|
+
|
43
|
+
Or parse a response with Nokogiri:
|
35
44
|
|
36
45
|
response.xml.css("Item > Title").each do |title|
|
37
46
|
some business value
|
@@ -39,10 +48,6 @@ Response API allows one to utilize the pure goodness of Nokogiri:
|
|
39
48
|
|
40
49
|
response.xml.xpath("//Item")
|
41
50
|
|
42
|
-
Specify a particular eBay locale (defaults to US):
|
43
|
-
|
44
|
-
AgentCooper::Shopper.new(:locale => :fr)
|
45
|
-
|
46
51
|
----
|
47
52
|
|
48
53
|
Based on papercavalier's [sucker](http://github.com/papercavalier/sucker).
|
data/features/support/env.rb
CHANGED
@@ -14,12 +14,14 @@ module AgentCooperMethods
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def cassette_name
|
17
|
-
Digest::MD5.hexdigest(@request.
|
17
|
+
Digest::MD5.hexdigest(@request.options.to_json)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
World(AgentCooperMethods)
|
22
22
|
|
23
23
|
Before do
|
24
|
-
|
24
|
+
AgentCooper::Config.set do |config|
|
25
|
+
config.app_id = 'SOME_OBSCURE_APP_ID'
|
26
|
+
end
|
25
27
|
end
|
data/lib/agent_cooper/finder.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
module AgentCooper
|
2
2
|
class Finder < Request
|
3
3
|
|
4
|
-
HOST = 'http://svcs.ebay.com/services/search/FindingService/v1'
|
5
4
|
VERSION = '1.9.0'
|
6
5
|
|
7
|
-
|
6
|
+
base_uri 'svcs.ebay.com'
|
7
|
+
default_params 'SECURITY-APPNAME' => Config.app_id,
|
8
|
+
'SECURITY-VERSION' => VERSION,
|
9
|
+
'RESPONSE-DATA-FORMAT' => ENCODING,
|
10
|
+
'REST-PAYLOAD' => ''
|
8
11
|
|
9
|
-
|
10
|
-
{
|
11
|
-
'SECURITY-APPNAME' => APP_ID,
|
12
|
-
'SECURITY-VERSION' => VERSION,
|
13
|
-
'RESPONSE-DATA-FORMAT' => ENCODING,
|
14
|
-
'REST-PAYLOAD' => ''
|
15
|
-
}.merge(parameters)
|
16
|
-
end
|
12
|
+
protected
|
17
13
|
|
18
|
-
def
|
19
|
-
|
14
|
+
def path
|
15
|
+
'/services/search/FindingService/v1'
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
@@ -1,24 +1,20 @@
|
|
1
1
|
module AgentCooper
|
2
2
|
class Merchandiser < Request
|
3
3
|
|
4
|
-
HOST = 'http://svcs.ebay.com/MerchandisingService'
|
5
4
|
SERVICE_NAME = 'MerchandisingService'
|
6
5
|
VERSION = '1.4.0'
|
7
|
-
|
8
|
-
protected
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
7
|
+
base_uri 'svcs.ebay.com'
|
8
|
+
default_params 'CONSUMER-ID' => Config.app_id,
|
9
|
+
'SERVICE-NAME' => SERVICE_NAME,
|
10
|
+
'SERVICE-VERSION' => VERSION,
|
11
|
+
'RESPONSE-DATA-FORMAT' => ENCODING,
|
12
|
+
'REST-PAYLOAD' => ''
|
13
|
+
|
14
|
+
protected
|
19
15
|
|
20
|
-
def
|
21
|
-
|
16
|
+
def path
|
17
|
+
'/MerchandisingService'
|
22
18
|
end
|
23
19
|
end
|
24
20
|
end
|
data/lib/agent_cooper/request.rb
CHANGED
@@ -1,47 +1,30 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
LOCALE_CODES = {
|
6
|
-
:us => 0,
|
7
|
-
:fr => 71,
|
8
|
-
:es => 186,
|
9
|
-
:gb => 3,
|
10
|
-
:de => 77,
|
11
|
-
:nl => 146,
|
12
|
-
:it => 101,
|
13
|
-
:au => 15,
|
14
|
-
:ca => 2
|
15
|
-
}
|
16
|
-
|
17
|
-
attr_accessor :locale
|
18
|
-
|
19
|
-
def initialize(args={})
|
20
|
-
args.each { |k, v| send("#{k}=", v) }
|
21
|
-
end
|
3
|
+
module AgentCooper
|
4
|
+
class Request
|
22
5
|
|
23
|
-
|
24
|
-
@parameters ||= {}
|
25
|
-
end
|
6
|
+
ENCODING = 'XML'
|
26
7
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
8
|
+
include HTTParty
|
9
|
+
format :xml
|
30
10
|
|
31
|
-
|
32
|
-
parameters.merge!(hash)
|
33
|
-
end
|
11
|
+
attr_accessor :locale
|
34
12
|
|
35
|
-
|
36
|
-
|
37
|
-
|
13
|
+
def options
|
14
|
+
@options ||= {}
|
15
|
+
end
|
38
16
|
|
39
|
-
|
40
|
-
|
41
|
-
|
17
|
+
def <<(hash)
|
18
|
+
options.merge!(hash)
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset!
|
22
|
+
@options = {}
|
23
|
+
end
|
42
24
|
|
43
|
-
|
44
|
-
|
45
|
-
|
25
|
+
def get
|
26
|
+
r = self.class.get(path, :query => options)
|
27
|
+
Response.new(r)
|
28
|
+
end
|
46
29
|
end
|
47
30
|
end
|
@@ -1,30 +1,36 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
|
3
|
-
|
3
|
+
module AgentCooper
|
4
|
+
class Response
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def body
|
11
|
+
response.body
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def to_hash
|
15
|
+
response.parsed_response
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def code
|
19
|
+
response.code
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def valid?
|
23
|
+
code == 200
|
24
|
+
end
|
25
|
+
|
26
|
+
def xml
|
27
|
+
@xml ||= Nokogiri::XML(body)
|
28
|
+
end
|
24
29
|
|
25
|
-
|
30
|
+
protected
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
def response
|
33
|
+
@response
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
data/lib/agent_cooper/shopper.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
module AgentCooper
|
2
2
|
class Shopper < Request
|
3
3
|
|
4
|
-
HOST = 'http://open.api.ebay.com/shopping'
|
5
4
|
VERSION = '717'
|
6
|
-
|
7
|
-
protected
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
6
|
+
base_uri 'open.api.ebay.com'
|
7
|
+
default_params 'APPID' => Config.app_id,
|
8
|
+
'RESPONSEENCODING' => ENCODING,
|
9
|
+
'VERSION' => VERSION,
|
10
|
+
'SITEID' => 0
|
11
|
+
|
12
|
+
protected
|
17
13
|
|
18
|
-
def
|
19
|
-
|
14
|
+
def path
|
15
|
+
'/shopping'
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
data/lib/agent_cooper/version.rb
CHANGED
data/lib/agent_cooper.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AgentCooper
|
4
|
+
describe Config do
|
5
|
+
subject { Config }
|
6
|
+
|
7
|
+
describe ".app_id=" do
|
8
|
+
it "sets a value for @@app_id" do
|
9
|
+
subject.app_id = "12345"
|
10
|
+
subject.class_variables.should include("@@app_id")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".app_id" do
|
15
|
+
it "returns @@app_id value" do
|
16
|
+
subject.app_id = "6789"
|
17
|
+
subject.app_id.should == "6789"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -8,22 +8,16 @@ module AgentCooper
|
|
8
8
|
@request = subject.new
|
9
9
|
end
|
10
10
|
|
11
|
-
describe "#
|
11
|
+
describe "#options" do
|
12
12
|
it "returns a hash" do
|
13
|
-
@request.
|
13
|
+
@request.options.should be_a(Hash)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "#<<" do
|
18
|
-
it "merges a hash into the existing
|
18
|
+
it "merges a hash into the existing options" do
|
19
19
|
@request << {:foo => "bar"}
|
20
|
-
@request.
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#locale" do
|
25
|
-
it "defaults to :us" do
|
26
|
-
@request.locale.should == :us
|
20
|
+
@request.options[:foo].should == "bar"
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
@@ -31,7 +25,7 @@ module AgentCooper
|
|
31
25
|
it "resets the parameters to a blank hash" do
|
32
26
|
@request << {:foo => 'bar'}
|
33
27
|
@request.reset!
|
34
|
-
@request.
|
28
|
+
@request.options.should_not have_key(:foo)
|
35
29
|
end
|
36
30
|
end
|
37
31
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agent_cooper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Closner
|
@@ -204,12 +204,14 @@ files:
|
|
204
204
|
- features/support/env.rb
|
205
205
|
- features/support/vcr.rb
|
206
206
|
- lib/agent_cooper.rb
|
207
|
+
- lib/agent_cooper/config.rb
|
207
208
|
- lib/agent_cooper/finder.rb
|
208
209
|
- lib/agent_cooper/merchandiser.rb
|
209
210
|
- lib/agent_cooper/request.rb
|
210
211
|
- lib/agent_cooper/response.rb
|
211
212
|
- lib/agent_cooper/shopper.rb
|
212
213
|
- lib/agent_cooper/version.rb
|
214
|
+
- spec/agent_cooper/config_spec.rb
|
213
215
|
- spec/agent_cooper/finder_spec.rb
|
214
216
|
- spec/agent_cooper/merchandiser_spec.rb
|
215
217
|
- spec/agent_cooper/request_spec.rb
|
@@ -261,6 +263,7 @@ test_files:
|
|
261
263
|
- features/step_definitions/shopper_steps.rb
|
262
264
|
- features/support/env.rb
|
263
265
|
- features/support/vcr.rb
|
266
|
+
- spec/agent_cooper/config_spec.rb
|
264
267
|
- spec/agent_cooper/finder_spec.rb
|
265
268
|
- spec/agent_cooper/merchandiser_spec.rb
|
266
269
|
- spec/agent_cooper/request_spec.rb
|