Skip to content

Commit

Permalink
General cleanup and add EM::Synchrony support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Closner committed Jul 23, 2011
1 parent 152c04e commit 9121112
Show file tree
Hide file tree
Showing 62 changed files with 4,399 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.bundle
Gemfile.lock
pkg/*
*.yml
ebay.yml
1 change: 0 additions & 1 deletion .rvmrc

This file was deleted.

15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,51 @@ Usage
-----
Set up.

```ruby
AgentCooper.configure do |config|
config.app_id = "SOME_OBSCURE_APP_ID"
end
```

Initialize a request

```ruby
request = AgentCooper::Finder.new
request = AgentCooper::Shopper.new
request = AgentCooper::Merchandiser.new

```
Build request params.

```ruby
request << {
'OPERATION-NAME' => 'getSearchKeywordsRecommendation',
'KEYWORDS' => 'arry potter'
}
```

Get a response.

```ruby
response = request.get
```

Return a hash:

```ruby
response.to_hash

returns: {'getSearchKeywordsRecommendationResponse' => {'xmnls' => 'http://www.ebay.com/marketplace/search/v1/services', 'ack' => 'Success', 'version' => '1.9.0', 'keywords' => 'harry potter'}}

```

Or parse a response with Nokogiri:

```ruby
response.xml.css("Item > Title").each do |title|
some business value
end

response.xml.xpath("//Item")

```
----

Based on papercavalier's [sucker](http://github.com/papercavalier/sucker).
3 changes: 0 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ end
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty"
end

task :default => [:spec, :features]

25 changes: 12 additions & 13 deletions agent_cooper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ Gem::Specification.new do |s|
s.rubyforge_project = "agent_cooper"

{
'httparty' => '~> 0.7.7',
'nokogiri' => '~> 1.4.4'
'httpclient' => '~> 2.2',
'nokogiri' => '~> 1.4'
}.each {|lib, version| s.add_runtime_dependency lib, version }


{
'bundler' => '~> 1.0.0',
'addressable' => '2.2.4',
'cucumber' => '~> 0.10.0',
'rake' => '~> 0.8.7',
'relish' => '~> 0.3.0.pre',
'rspec' => '~> 2.5.0',
'vcr' => '~> 1.9.0',
'webmock' => '~> 1.6.0'
'cucumber' => '~> 1.0',
'em-http-request' => '~> 1.0.0.beta.4',
'em-synchrony' => '~> 0.3.0.beta.1',
'rake' => '~> 0.9',
'rspec' => '~> 2.6',
'vcr' => '~> 1.10',
'webmock' => '~> 1.6'
}.each {|lib, version| s.add_development_dependency lib, version }

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
Expand Down
1 change: 0 additions & 1 deletion bin/erb-ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/gem-ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/irb-ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/rake-ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/rdoc-ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/ri-ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/ruby-1.9.2-p180@agent_cooper

This file was deleted.

1 change: 0 additions & 1 deletion bin/testrb-ruby-1.9.2-p180@agent_cooper

This file was deleted.

10 changes: 4 additions & 6 deletions features/finder.feature
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Feature: Ebay Finder
As an API consumer

Background:
Background:
Given a new finder request

Scenario: getSearchKeywordsRecommendation
Given the following parameters:
| OPERATION-NAME | keywords |
| getSearchKeywordsRecommendation | acordian |
When I tape the "finder" request as: "get_search_keywords_recommendation"
Then the response code should be "200"
And the response should have 1 "keywords" nodes

Scenario: findItemsByKeywords
Given the following parameters:
| OPERATION-NAME | keywords |
Expand All @@ -27,7 +27,7 @@ Feature: Ebay Finder
When I tape the "finder" request as: "find_items_by_category"
Then the response code should be "200"
And the response should have 100 "item" nodes

Scenario: findItemsAdvanced
Given the following parameters:
| OPERATION-NAME | keywords |
Expand Down Expand Up @@ -60,5 +60,3 @@ Feature: Ebay Finder
When I tape the "finder" request as: "get_histograms"
Then the response code should be "200"
And the response should have 6 "childCategoryHistogram" nodes


3 changes: 1 addition & 2 deletions features/merchandiser.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Ebay Merchandiser
As an API consumer

Background:
Background:
Given a new merchandiser request

Scenario: getMostWatchedItems
Expand Down Expand Up @@ -31,4 +31,3 @@ Feature: Ebay Merchandiser
| getTopSellingProducts | 3 |
When I tape the "merchandiser" request as: "get_top_selling_products"
Then the response code should be "200"

4 changes: 2 additions & 2 deletions features/shopper.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Feature: Ebay Shopper
As an API consumer

Background:
Background:
Given a new shopper request

Scenario: FindProducts
Given the following parameters:
| CALLNAME | QueryKeywords |
Expand Down
8 changes: 4 additions & 4 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
require 'agent_cooper'


module AgentCooperMethods
module AgentCooperMethods
def ebay
@ebay ||= YAML::load_file(File.dirname(__FILE__) + "/../../spec/support/ebay.yml")
@ebay ||= YAML::load_file(File.dirname(__FILE__) + "/../../spec/fixtures/ebay.yml")
end

def ebay_app_id
ebay['app_id']
end

def cassette_name
Digest::MD5.hexdigest(@request.options.to_json)
Digest::MD5.hexdigest(@request.parameters.to_json)
end
end

World(AgentCooperMethods)

Before do
AgentCooper::Config.set do |config|
AgentCooper.configure do |config|
config.app_id = ebay_app_id
end
end
10 changes: 10 additions & 0 deletions features/support/vcr.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
require 'vcr'

def ebay
@ebay ||= YAML::load_file(File.dirname(__FILE__) + "/../../spec/fixtures/ebay.yml")
end

def ebay_app_id
ebay['app_id']
end


VCR.config do |c|
c.cassette_library_dir = File.dirname(__FILE__) + '/../../spec/fixtures/cassettes'
c.default_cassette_options = {
:record => :none,
:match_requests_on => [:host] }
c.stub_with :webmock
c.filter_sensitive_data('YOUR-APP-ID') { ebay_app_id }
end
18 changes: 13 additions & 5 deletions lib/agent_cooper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# Utilities
require 'agent_cooper/config'
require 'agent_cooper/request'
require 'agent_cooper/response'
require 'agent_cooper/finder'
require 'agent_cooper/shopper'
require 'agent_cooper/merchandiser'
require 'agent_cooper/request'

require 'agent_cooper/nokogiri_decorator'

# Requests
require 'agent_cooper/requests/finder'
require 'agent_cooper/requests/shopper'
require 'agent_cooper/requests/merchandiser'

#Version
require "agent_cooper/version"

module AgentCooper
class << self
def configure(&block)
yield Config
Config.configure(&block)
end
end
end
8 changes: 3 additions & 5 deletions lib/agent_cooper/config.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module AgentCooper
class Config
class << self
def app_id=(app_id)
@app_id = app_id
end
attr_accessor :app_id

def app_id
@app_id ||= nil
def configure(&block)
yield self
end
end
end
Expand Down
21 changes: 0 additions & 21 deletions lib/agent_cooper/finder.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/agent_cooper/merchandiser.rb

This file was deleted.

47 changes: 47 additions & 0 deletions lib/agent_cooper/nokogiri_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module AgentCooper

# Based on https://gist.github.com/335286

class Nokogiri::XML::Document
def to_hash
root.to_hash
end
end

class Nokogiri::XML::Element
def to_hash
({}).tap do |hash|

attributes.each_pair do |key, attribute|
hash[key] = attribute.value
end

children.each do |child|
result = child.to_hash

if child.name == 'text'
if hash.empty?
return result
else
hash['__content__'] = result
end
elsif hash[child.name]
if hash[child.name].is_a?(Array)
hash[child.name] << result
else
hash[child.name] = [hash[child.name]] << result
end
else
hash[child.name] = result
end
end
end
end
end

class Nokogiri::XML::Text
def to_hash
content.to_s
end
end
end
Loading

0 comments on commit 9121112

Please sign in to comment.