linkshare_api 0.0.1 → 0.1.0

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.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # LinkShare API
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/linkshare_api.png)](http://badge.fury.io/rb/linkshare_api)
4
+ [![Build Status](https://travis-ci.org/rmarescu/linkshare_api.png)](https://travis-ci.org/rmarescu/linkshare_api)
4
5
 
5
6
  Ruby wrapper for [LinkShare Publisher Web Services](http://helpcenter.linkshare.com/publisher/categories.php?categoryid=71).
6
7
  Supported web services:
7
- * [Automated LinkGenerator](#automated_link_generator)
8
+ * [Automated LinkGenerator](#automated-link-generator)
9
+ * [Merchandiser Query Tool](#merchandiser-query-tool)
8
10
 
9
11
  If you need services that are not yet supported, feel free to [contribute](#contributing).
10
12
  For questions or bugs please [create an issue](../../issues/new).
@@ -46,6 +48,57 @@ url = "http://www.walmart.com/cp/Electronics/3944?povid=P1171-C1093.2766-L33"
46
48
  affiliate_url = LinkshareAPI.link_generator(2149, url)
47
49
  ```
48
50
 
51
+ ### Merchandiser Query Tool
52
+
53
+ Search for products using [Merchandiser Query Tool](http://helpcenter.linkshare.com/publisher/categories.php?categoryid=74) service.
54
+
55
+ ```ruby
56
+ response = LinkshareAPI.product_search(keyword: "laptop")
57
+ # Return the number of total records that match the search criteria
58
+ puts response.total_matches # -1 means more than 4000 results (see doc)
59
+ # Return the number of pages
60
+ puts response.total_pages
61
+ # Return the number of current page
62
+ puts response.page_number
63
+ # See the actual API call to Linkshare
64
+ puts response.request.uri
65
+ # Return items
66
+ response.data.each do |item|
67
+ puts "Title: #{item.productname}"
68
+ puts "Price: #{item.price.__content__} #{item.price.currency}"
69
+ puts "URL: #{item.linkurl}"
70
+ end
71
+ ```
72
+
73
+ `product_search` accepts a hash as argument, and can include all available options. For a complete list of options please visit http://helpcenter.linkshare.com/publisher/questions.php?questionid=652.
74
+
75
+ ```ruby
76
+ # Search "laptop" only for Wal-Mart, within Electronics category,
77
+ # sorted by price ascending, and limit to 10 items per page.
78
+ options = {
79
+ keyword: "laptop",
80
+ mid: 2149, # Wal-Mart
81
+ cat: "Electronics",
82
+ max: 10,
83
+ sort: :retailprice,
84
+ sorttype: :asc
85
+ }
86
+ response = LinkshareAPI.product_search(options)
87
+ response.data.each do |item|
88
+ # Do stuff
89
+ end
90
+ ```
91
+
92
+ If there are multiple pages, you can retrieve all pages by using the `all` method, as follows:
93
+
94
+ ```ruby
95
+ response.all.each do |item|
96
+ # Do stuff
97
+ end
98
+ ```
99
+
100
+ When using the `all` method, `response` object is updated with the data returned by the last API request (last page). `response.all` returns the `data` array.
101
+
49
102
  ### Extra Configuration
50
103
 
51
104
  * `LinkshareAPI.api_timeout` - the timeout set when initiating requests to LinkShare Web Services (default value is 30 seconds)
@@ -0,0 +1,49 @@
1
+ require "addressable/uri"
2
+ require "httparty"
3
+
4
+ module LinkshareAPI
5
+ # For implementation details please visit
6
+ # http://helpcenter.linkshare.com/publisher/questions.php?questionid=652
7
+ class ProductSearch
8
+ include HTTParty
9
+
10
+ attr_reader :api_base_url, :api_timeout, :keyword, :token
11
+
12
+ def initialize
13
+ @token = LinkshareAPI.token
14
+ @api_base_url = LinkshareAPI::WEB_SERVICE_URIS[:product_search]
15
+ @api_timeout = LinkshareAPI.api_timeout
16
+
17
+ if @token.nil?
18
+ raise AuthenticationError.new(
19
+ "No token. Set your token by using 'LinkshareAPI.token = <TOKEN>'. " +
20
+ "You can retrieve your token from LinkhShare's Web Services page under the Links tab. " +
21
+ "See http://helpcenter.linkshare.com/publisher/questions.php?questionid=648 for details."
22
+ )
23
+ end
24
+ end
25
+
26
+ def query(params)
27
+ raise ArgumentError, "Hash expected, got #{params.class} instead" unless params.is_a?(Hash)
28
+
29
+ params.merge!(token: token)
30
+ begin
31
+ response = self.class.get(
32
+ api_base_url,
33
+ query: params,
34
+ timeout: api_timeout
35
+ )
36
+ rescue Timeout::Error
37
+ raise ConnectionError.new("Timeout error (#{timeout}s)")
38
+ end
39
+
40
+ if response.code != 200
41
+ raise Error.new(response.message, response.code)
42
+ end
43
+ error = response["result"]["Errors"]
44
+ raise InvalidRequestError.new(error["ErrorText"], error["ErrorID"].to_i) if error
45
+
46
+ Response.new(response)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ require "recursive_open_struct"
2
+
3
+ module LinkshareAPI
4
+ class Response
5
+ attr_reader :total_matches, :total_pages, :page_number, :data, :request
6
+
7
+ def initialize(response)
8
+ @request = response.request
9
+ result = response["result"]
10
+
11
+ @total_matches = result["TotalMatches"].to_i
12
+ @total_pages = result["TotalPages"].to_i
13
+ @page_number = result["PageNumber"].to_i
14
+ @data = parse(result["item"])
15
+ end
16
+
17
+ def all
18
+ while page_number < total_pages
19
+ uri = Addressable::URI.parse(request.uri)
20
+ params = uri.query_values
21
+ params["pagenumber"] = page_number + 1
22
+ next_page_response = LinkshareAPI::ProductSearch.new.query(params)
23
+ @page_number = next_page_response.page_number
24
+ @data += next_page_response.data
25
+ end
26
+ @data
27
+ end
28
+
29
+ private
30
+
31
+ def parse(raw_data)
32
+ data = []
33
+ data = [RecursiveOpenStruct.new(raw_data)] if raw_data.is_a?(Hash) # If we got exactly one result, put it in an array.
34
+ raw_data.each { |i| data << RecursiveOpenStruct.new(i) } if raw_data.is_a?(Array)
35
+ data
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module LinkshareAPI
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/linkshare_api.rb CHANGED
@@ -3,6 +3,8 @@ require "linkshare_api/version"
3
3
 
4
4
  # Resources
5
5
  require "linkshare_api/link_generator"
6
+ require "linkshare_api/product_search"
7
+ require "linkshare_api/response"
6
8
 
7
9
  # Errors
8
10
  require "linkshare_api/errors/error"
@@ -12,7 +14,8 @@ require "linkshare_api/errors/invalid_request_error"
12
14
 
13
15
  module LinkshareAPI
14
16
  WEB_SERVICE_URIS = {
15
- link_generator: "http://getdeeplink.linksynergy.com/createcustomlink.shtml"
17
+ link_generator: "http://getdeeplink.linksynergy.com/createcustomlink.shtml",
18
+ product_search: "http://productsearch.linksynergy.com/productsearch"
16
19
  }
17
20
 
18
21
  @api_timeout = 30
@@ -32,4 +35,9 @@ module LinkshareAPI
32
35
  link_generator = LinkshareAPI::LinkGenerator.new
33
36
  link_generator.build(mid, murl)
34
37
  end
38
+
39
+ def self.product_search(options = {})
40
+ product_search = LinkshareAPI::ProductSearch.new
41
+ product_search.query(options)
42
+ end
35
43
  end
@@ -19,7 +19,9 @@ Gem::Specification.new do |s|
19
19
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
+ s.add_dependency "addressable", "~> 2.3.5"
22
23
  s.add_dependency "httparty", "~> 0.11.0"
24
+ s.add_dependency "recursive-open-struct", "~> 0.4.3"
23
25
 
24
26
  s.add_development_dependency "bundler", "~> 1.3"
25
27
  s.add_development_dependency "rake"
@@ -23,17 +23,17 @@ class LinkshareAPITest < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_link_generator_invalid_mid
26
- LinkshareAPI.token = "token"
26
+ LinkshareAPI.token = token
27
27
  assert_raise ArgumentError do
28
28
  LinkshareAPI.link_generator(nil, nil)
29
29
  end
30
30
  end
31
31
 
32
32
  def test_link_generator_missing_url
33
- LinkshareAPI.token = "your_token"
33
+ LinkshareAPI.token = token
34
34
  stub_request(
35
35
  :get,
36
- "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=your_token&mid=123&murl="
36
+ "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=#{token}&mid=123&murl="
37
37
  ).
38
38
  to_return(
39
39
  status: 200,
@@ -47,12 +47,12 @@ class LinkshareAPITest < Test::Unit::TestCase
47
47
  end
48
48
 
49
49
  def test_link_generator_valid_request
50
- LinkshareAPI.token = "your_token"
50
+ LinkshareAPI.token = token
51
51
  mid = 2149
52
52
  murl = "http://www.walmart.com/cp/blu-ray/616859?povid=P1171-C1110.2784+1455.2776+1115.2956-L44"
53
53
  stub_request(
54
54
  :get,
55
- "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=your_token&mid=#{mid}&murl=#{murl}"
55
+ "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=#{token}&mid=#{mid}&murl=#{murl}"
56
56
  ).
57
57
  to_return(
58
58
  status: 200,
@@ -62,4 +62,165 @@ class LinkshareAPITest < Test::Unit::TestCase
62
62
  url = LinkshareAPI.link_generator(mid, murl)
63
63
  assert_equal "http://linksynergy.walmart.com/fs-bin/click?id=yourid&subid=0&offerid=223073.1&type=10&tmpid=273&RD_PARM0=http%3A%2F%2Fwww.walmart.com%2Fcp%2Fblu-ray%2F616859%3Fpovid%3DP1171-C1110.2784%2B1455.2776%2B1115.2956-L44&RD_PARM1=http%3A%2F%2Fwww.walmart.com%2Fcp%2Fblu-ray%2F616859%3F&RD_PARM2=povid%3DP1171-C1110.2784%2B1455.2776%2B1115.2956-L44", url
64
64
  end
65
+
66
+ def test_product_search_invalid_token
67
+ LinkshareAPI.token = nil
68
+ assert_raise LinkshareAPI::AuthenticationError do
69
+ LinkshareAPI.product_search(keyword: "laptop")
70
+ end
71
+ end
72
+
73
+ def test_product_search_invalid_argument
74
+ LinkshareAPI.token = "token"
75
+ assert_raise ArgumentError do
76
+ LinkshareAPI.product_search("foo")
77
+ end
78
+ end
79
+
80
+ def test_product_search_invalid_response_code
81
+ LinkshareAPI.token = token
82
+ stub_request(
83
+ :get,
84
+ "http://productsearch.linksynergy.com/productsearch?keyword=%26%26&token=#{token}"
85
+ ).
86
+ to_return(
87
+ status: [500, "Internal Server Error"],
88
+ body: "",
89
+ headers: {}
90
+ )
91
+ e = assert_raise LinkshareAPI::Error do
92
+ LinkshareAPI.product_search(keyword: "&&")
93
+ end
94
+ assert_equal 500, e.code
95
+ assert_equal "Internal Server Error", e.message
96
+ end
97
+
98
+ def test_product_search_invalid_request
99
+ LinkshareAPI.token = token
100
+ xml_response = <<-XML
101
+ <?xml version="1.0" encoding="UTF-8"?>
102
+ <result><Errors><ErrorID>718615</ErrorID><ErrorText>No keyword specified.</ErrorText></Errors></result>
103
+ XML
104
+ stub_request(
105
+ :get,
106
+ "http://productsearch.linksynergy.com/productsearch?keyword=%26%26&token=#{token}"
107
+ ).
108
+ to_return(
109
+ status: 200,
110
+ body: xml_response,
111
+ headers: { "Content-type" => "text/xml; charset=UTF-8" }
112
+ )
113
+ e = assert_raise LinkshareAPI::InvalidRequestError do
114
+ LinkshareAPI.product_search(keyword: "&&")
115
+ end
116
+ assert_equal 718615, e.code
117
+ assert_equal "No keyword specified.", e.message
118
+ end
119
+
120
+ def test_product_search_no_results
121
+ LinkshareAPI.token = token
122
+ xml_response = <<-XML.strip
123
+ <?xml version="1.0" encoding="UTF-8"?>
124
+ <result><TotalMatches>0</TotalMatches><TotalPages>0</TotalPages><PageNumber>1</PageNumber></result>
125
+ XML
126
+ keyword = "weird_keyword_with_no_results"
127
+ stub_request(
128
+ :get,
129
+ "http://productsearch.linksynergy.com/productsearch?keyword=#{keyword}&token=#{token}"
130
+ ).
131
+ to_return(
132
+ status: 200,
133
+ body: xml_response,
134
+ headers: { "Content-type" => "text/xml; charset=UTF-8" }
135
+ )
136
+ response = LinkshareAPI.product_search(keyword: keyword)
137
+ assert_equal 0, response.total_matches
138
+ assert_equal 0, response.total_pages
139
+ assert_equal 1, response.page_number
140
+ assert_equal [], response.data
141
+ end
142
+
143
+ def test_product_search_valid_response
144
+ LinkshareAPI.token = token
145
+ xml_response = <<-XML.strip
146
+ <?xml version="1.0" encoding="UTF-8"?>
147
+ <result><TotalMatches>2</TotalMatches><TotalPages>1</TotalPages><PageNumber>1</PageNumber><item><mid>36342</mid><merchantname>Buy.com</merchantname><linkid>250754125</linkid><createdon>2013-07-13/16:15:14</createdon><sku>250754125</sku><productname> Dell Inspiron 17R-5720, Core i5- 2.5GHz, 8GB/1TB, 17.3 , Webcam, Bluetooth, 1Y Warranty ; Lotus Pink Edition </productname><category><primary> Computers~~Computer Systems </primary><secondary> </secondary></category><price currency="USD">629.99</price><upccode>00621988902522</upccode><description><short>Enjoy HD movies on this expansive 17 laptop with bold color options, HD+ display, Intel Core i5 processor, and more storage space for all your multimedia. From movie night to family finances, everyones priorities are easier to tackle with the 3rd Gen Intel Core i5 processor, Windows 8, 8GB of memory and 1TB hard drive capacity. Support new technologies like USB 3.0, higher performance and Intel HD graphics for your everyday computing needs with power to grow with you in the future.</short><long>Enjoy HD movies on this expansive 17 laptop with bold color options, HD+ display, Intel Core i5 processor, and more storage space for all your multimedia. From movie night to family finances, everyones priorities are easier to tackle with the 3rd Gen Intel Core i5 processor, Windows 8, 8GB of memory and 1TB hard drive capacity. Support new technologies like USB 3.0, higher performance and Intel HD graphics for your everyday computing needs with power to grow with you in the future. Watch your movies, games, and streaming video go from fast to blazing fast with up to 8GB of fast, efficient DDR3 SDRAM at 1600MHz. Make the Inspiron 17R your communications hub. Connecting with friends and family has never been easier, thanks to a robust WiFi connection and built-in HD webcam, over five hours of battery life, and a 17.3 screen that brings you face-to-face with friends and family. The Inspiron 17Rs 17.3 Truelife screen brings whatever you are watching to life, wherever you go. Plus, take your entertainment from cool to whoa by connecting to an external HDMI-capable TV or monitor via the available HDMI v1.4a port. You may never need to buy a movie ticket again. The 17.3 Truelife display makes your photos, videos, movies and other onscreen images pop. Treat your eyes to an intense visual experience wherever you go. Peace of mind comes standard with every Inspiron 17R.</long></description><saleprice currency="USD">629.99</saleprice><keywords/><linkurl>http://affiliate.rakuten.com/link?id=yourid&amp;offerid=272843.250754125&amp;type=15&amp;murl=http%3A%2F%2Fnotebookavenue.store.buy.com%2Fp%2Fdell-inspiron-17r-5720-core-i5-2-5ghz-8gb-1tb-17-3-webcam-bluetooth-1y%2F250754125.html</linkurl><imageurl>http://images.rakuten.com/PI/0/1000/250754125.jpg</imageurl></item><item><mid>36342</mid><merchantname>Buy.com</merchantname><linkid>250993173</linkid><createdon>2013-07-06/19:57:35</createdon><sku>250993173</sku><productname> Dell Inspiron 17R-5720, Core i7 -3612QM- 2.1GHz, 8GB/1TB, 17.3 , Webcam, Bluetooth, 1 Year Warranty ; Lotus Pink Edition </productname><category><primary> Computers~~Computer Systems </primary><secondary> </secondary></category><price currency="USD">729.99</price><upccode>00022367227517</upccode><description><short>Enjoy HD movies on this expansive 17 laptop with bold color options, HD+ display, Intel Core i7 processor, and more storage space for all your multimedia. From movie night to family finances, everyones priorities are easier to tackle with the 3rd Gen Intel Core i7 processor, Windows 7, 8GB of memory and 1TB hard drive capacity. Support new technologies like USB 3.0, higher performance and Intel HD graphics for your everyday computing needs with power to grow with you in the future.</short><long>Enjoy HD movies on this expansive 17 laptop with bold color options, HD+ display, Intel Core i7 processor, and more storage space for all your multimedia. From movie night to family finances, everyones priorities are easier to tackle with the 3rd Gen Intel Core i7 processor, Windows 7, 8GB of memory and 1TB hard drive capacity. Support new technologies like USB 3.0, higher performance and Intel HD graphics for your everyday computing needs with power to grow with you in the future. Watch your movies, games, and streaming video go from fast to blazing fast with up to 8GB of fast, efficient DDR3 SDRAM at 1600MHz. Make the Inspiron 17R your communications hub. Connecting with friends and family has never been easier, thanks to a robust WiFi connection and built-in HD webcam, over five hours of battery life, and a 17.3 screen that brings you face-to-face with friends and family. The Inspiron 17Rs 17.3 Truelife screen brings whatever you are watching to life, wherever you go. Plus, take your entertainment from cool to whoa by connecting to an external HDMI-capable TV or monitor via the available HDMI v1.4a port. You may never need to buy a movie ticket again. The 17.3 Truelife display makes your photos, videos, movies and other onscreen images pop. Treat your eyes to an intense visual experience wherever you go. Peace of mind comes standard with every Inspiron 17R.</long></description><saleprice currency="USD">729.99</saleprice><keywords/><linkurl>http://affiliate.rakuten.com/link?id=yourid&amp;offerid=272843.250993173&amp;type=15&amp;murl=http%3A%2F%2Fnotebookavenue.store.buy.com%2Fp%2Fdell-inspiron-17r-5720-core-i7-3612qm-2-1ghz-8gb-1tb-17-3-webcam%2F250993173.html</linkurl><imageurl>http://img.rakuten.com/PIC/53838093/0/1/250/53838093.jpg</imageurl></item></result>
148
+ XML
149
+ keyword = "weird_keyword_with_no_results"
150
+ stub_request(
151
+ :get,
152
+ "http://productsearch.linksynergy.com/productsearch?keyword=#{keyword}&token=#{token}"
153
+ ).
154
+ to_return(
155
+ status: 200,
156
+ body: xml_response,
157
+ headers: { "Content-type" => "text/xml; charset=UTF-8" }
158
+ )
159
+ response = LinkshareAPI.product_search(keyword: keyword)
160
+ assert_equal 2, response.total_matches
161
+ assert_equal 1, response.total_pages
162
+ assert_equal 1, response.page_number
163
+ assert_equal 2, response.data.count
164
+ assert_equal "250754125", response.data.first.sku
165
+ assert_equal "729.99", response.data.last.saleprice.__content__
166
+ end
167
+
168
+ def test_product_search_all_results
169
+ LinkshareAPI.token = token
170
+ keyword = "intel laptop"
171
+ options = {
172
+ keyword: keyword,
173
+ max: 3
174
+ }
175
+ xml_response_1 = <<-XML.strip
176
+ <?xml version="1.0" encoding="UTF-8"?>
177
+ <result><TotalMatches>7</TotalMatches><TotalPages>3</TotalPages><PageNumber>1</PageNumber><item><mid>36342</mid><merchantname>Buy.com</merchantname><linkid>250014339</linkid><createdon>2013-07-19/16:21:04</createdon><sku>250014339</sku><productname> HP Envy 17-J020US E0K82UA 17.3 LED Notebook - Intel Core i7 i7-4700MQ - Natural Silver - 8 GB RAM - 1 TB HDD - DVD-Writer - Genuine Windows 8 64-bit - 1600 x 900 Display - Bluetooth </productname><category><primary> Computers~~Computer Systems </primary><secondary> </secondary></category><price currency="USD">1044.44</price><upccode>00887758488485</upccode><description><short>In a class by itself. Elevate your expectations. Every ENVY laptop is crafted to surpass them with the finest features and powerful technology that deliver premium entertainment and computing experience.</short><long>In a class by itself. Elevate your expectations. Every ENVY laptop is crafted to surpass them with the finest features and powerful technology that deliver premium entertainment and computing experience.</long></description><saleprice currency="USD">1044.44</saleprice><keywords/><linkurl>http://affiliate.rakuten.com/link?id=yourid&amp;offerid=272843.250014339&amp;type=15&amp;murl=http%3A%2F%2Fantonline.store.buy.com%2Fp%2Fhp-envy-17-j020us-e0k82ua-17-3-led-notebook-intel-core-i7-i7-4700mq%2F250014339.html</linkurl><imageurl>http://img.rakuten.com/PIC/55207010/0/1/250/55207010.jpg</imageurl></item><item><mid>36342</mid><merchantname>Buy.com</merchantname><linkid>247569811</linkid><createdon>2013-08-11/20:22:31</createdon><sku>247569811</sku><productname> Lenovo ThinkPad W530 243857U 15.6 LED Notebook - Intel - Core i7 i7-3740QM 2.7GHz - 4 GB RAM - 500 GB HDD - DVD-Writer - NVIDIA Quadro K2000M, Intel HD 4000 Graphics - Genuine Windows 7 Professional 64-bit - 1920 x 1080 Display - Bluetooth </productname><category><primary> Computers~~Computer Systems </primary><secondary> </secondary></category><price currency="USD">1699</price><upccode>00887770534832</upccode><description><short>BRILLIANT BUSINESS LAPTOPS.Rock-solid reliability. Blazing-fast performance. Clever manageability tools. We pack a lot of intelligent features into every ThinkPad laptop, tablet, and Ultrabook so you get more out. More productivity, more cost savings, more IT headache-busting. That's why a ThinkPad investment isn't just smart. It's pure genius.</short><long>BRILLIANT BUSINESS LAPTOPS.Rock-solid reliability. Blazing-fast performance. Clever manageability tools. We pack a lot of intelligent features into every ThinkPad laptop, tablet, and Ultrabook so you get more out. More productivity, more cost savings, more IT headache-busting. That's why a ThinkPad investment isn't just smart. It's pure genius.</long></description><saleprice currency="USD">1659.99</saleprice><keywords/><linkurl>http://affiliate.rakuten.com/link?id=yourid&amp;offerid=272843.247569811&amp;type=15&amp;murl=http%3A%2F%2Fwww.rakuten.com%2Fprod%2Flenovo-thinkpad-w530-243857u-15-6-led-notebook-intel-core-i7-i7-3740qm%2F247569811.html</linkurl><imageurl>http://img.rakuten.com/PIC/41096678/0/1/250/41096678.jpg</imageurl></item><item><mid>36342</mid><merchantname>Buy.com</merchantname><linkid>227830151</linkid><createdon>2012-04-27/04:16:52</createdon><sku>227830151</sku><productname> Intel 520 Series 180GB 2.5 SATA III Solid State Drive </productname><category><primary> Computers~~Storage Devices </primary><secondary> </secondary></category><price currency="USD">218.99</price><upccode>00735858224369</upccode><description><short>GET FAST. PLAY FIERCE.Faster game and application loads, less lag, smoother visuals.Stay ahead of the competition when you level up to 6.0 gigabits per second (Gb/s) performance. Cherryville Solid-State Drives (SSDs) continue to evolve with the Intel SSD 500 Faily.</short><long>GET FAST. PLAY FIERCE.Faster game and application loads, less lag, smoother visuals.Stay ahead of the competition when you level up to 6.0 gigabits per second (Gb/s) performance. Cherryville Solid-State Drives (SSDs) continue to evolve with the Intel SSD 500 Faily. Available in a wide range of capacities, Cherryville SSDs offer built-in data protection features and delivers exceptional performance over hard drives.New Level of PerformanceBuilt with compute-quality Intel 25 nanometer (nm) NAND Flash Memory, Cherryville SSDs accelerate PC performance where it matters most. With random read performance up to 50,000 input/output operations per second (IOPS)1 and sequential read performance of up to 550 megabytes per second (MB/s), your PC will blaze through the most demanding applications and will handle intense multi-tasking needs. Couple that read performance with random writes up to 80,000 IOPS and sequential writes of 520 MB/s to unleash your applications. With Cherryville SSDs, Intel continues to deliver solutions designed to satisfy the most demanding gamers, media creators and technology enthusiasts.Superior Data Protection FeaturesThe new Cherryville SSDs offer the best security features of any Intel Solid-State Drive to date and comes pre-configured with Advanced Encryption Standard (AES) 256-bit encryption capabilities. In the event of theft or loss of your computer, you have the peace of mind that your personal data is secured by an advanced encryption technology.Additionally, the Cherryville SSDs contain End to End Data Protection ensuring integrity of stored data from the computer to the SSD and back.Proven Reliability with Lower Operating CostsWith no moving parts, the Cherryville SSDs reduce your risk of data loss due to laptop bumps or drop, all while consuming less power than a traditional hard drive so you can stay mobile longer. Now that your work is safe, use the world-class performance</long></description><saleprice currency="USD">218.99</saleprice><keywords/><linkurl>http://affiliate.rakuten.com/link?id=yourid&amp;offerid=272843.227830151&amp;type=15&amp;murl=http%3A%2F%2Fbruc-computers.store.buy.com%2Fp%2Fintel-520-series-180gb-2-5-sata-iii-solid-state-drive%2F227830151.html</linkurl><imageurl>http://img.rakuten.com/PIC/52297706/0/1/250/52297706.jpg</imageurl></item></result>
178
+ XML
179
+ xml_response_2 = <<-XML.strip
180
+ <?xml version="1.0" encoding="UTF-8"?>
181
+ <result><TotalMatches>7</TotalMatches><TotalPages>3</TotalPages><PageNumber>2</PageNumber><item><mid>36699</mid><merchantname>Expansys</merchantname><linkid>226002</linkid><createdon>2011-11-17/16:35:22</createdon><sku>226002</sku><productname> Samsung Series 7 Slate PC (1.6GHz, 4GB RAM, 64GB SSD, Windows 7) </productname><category><primary> Windows 8 </primary><secondary> </secondary></category><price currency="CAD">1189.99</price><upccode/><description><short>The Windows 7 OS allows you to run all your favorite office software. You can share documents with co-workers without any compatibility issues. And our Samsung touch interface gives you easy, instant access to all your programs. Exclusive Fast Start Technology When inspiration hits, make sure you have a laptop that can keep up. With Samsung's exclusive Fast Start technology, close the lid to enter a hybrid sleep mode, then simply open it to be up and running again in as little as two seconds....</short><long>The Windows 7 OS allows you to run all your favorite office software. You can share documents with co-workers without any compatibility issues. And our Samsung touch interface gives you easy, instant access to all your programs. Exclusive Fast Start Technology When inspiration hits, make sure you have a laptop that can keep up. With Samsung's exclusive Fast Start technology, close the lid to enter a hybrid sleep mode, then simply open it to be up and running again in as little as two seconds. A Full PC in a Sleek Form Factor Samsung Series 7 slate PCs offer the power and speed of a full-size PC, yet they're a mere half-inch thick and weigh less than a pound. They're an amazing marriage of power and design. 1366 x 768 WXGA Display - 4 GB RAM - 64 GB SSD - Intel HD 3000 Graphics Card - Bluetooth - Webcam - Genuine Windows 7 Home Premium - HDMI</long></description><saleprice currency="CAD">1189.99</saleprice><keywords/><linkurl>http://click.linksynergy.com/link?id=yourid&amp;offerid=223777.226002&amp;type=15&amp;murl=http%3A%2F%2Fwww.expansys.ca%2Fsamsung-series-7-slate-pc-226002%2F%3Futm_source%3Daffiliate%26utm_medium%3Dshopping%26utm_campaign%3Dlinkshare-ca</linkurl><imageurl>http://i1.expansys.com/img/l/226002/samsung-series-7-slate-pc.jpg</imageurl></item><item><mid>24572</mid><merchantname>Cascio Interstate Music</merchantname><linkid>10150425</linkid><createdon>2013-08-09/19:40:04</createdon><sku>893566</sku><productname> "Lenovo - 59371478 IdeaPad S500 Touch 15.6"" Multi-Touch Laptop" </productname><category><primary> New Product </primary><secondary> </secondary></category><price currency="USD">599.99</price><upccode>887770679847</upccode><description><short>"IdeaPad S500 Touch:&amp;nbsp; Thin, Light and Affordable 15.6"" Multi-Touch Laptop. The IdeaPad S500 Touch laptop features a capacitive 10-point touchscreen in a slim, attractive design.&amp;nbsp; Backed by powerful Intel processor, long battery life, integrated Intel HD graphics and the comfortable AccuType keyboard, it delivers the smart performance of a laptop, while also providing the touch convenience of a tablet.&amp;nbsp; All at an affordable price.&amp;nbsp;&amp;nbsp; &amp;nbsp;Features: 10-Point Multi-touch Screen optimized for Windows 8 Less than 1&amp;rdquo; profile (.9&amp;rdquo;) with smooth cover Stereo speakers and Dolby Advanced Audio v2 Comfortable, user-friendly AccuType keyboard Integrated 720p HD webcam Intelligent Touchpad with easy multi-gesture control Integrated 802.11b/g/n WiFi High-speed USB 3.0, USB 2.0, 2-in-1 card-reader and HDMI out OneKey Recovery System makes data backup and recovery simple Lenovo Energy Management minimizes power use and protects battery life"</short><long/></description><saleprice currency="USD">599.99</saleprice><keywords>"Lenovo S500 Touch 15.6&amp;quot; i3 4GB, Lenovo - 59371478 IdeaPad S500 Touch 15.6"" Multi-Touch Laptop, 59371478, LENOVO, 887770679847, Computers and Software, Laptops/Notebooks"</keywords><linkurl>http://click.linksynergy.com/link?id=yourid&amp;offerid=170159.10150425&amp;type=15&amp;murl=http%3A%2F%2Fwww.interstatemusic.com%2F893566-Lenovo-59371478-IdeaPad-S500-Touch-15-6-Multi-Touch-Laptop-59371478.aspx</linkurl><imageurl>http://az58332.vo.msecnd.net/e88dd2e9fff747f090c792316c22131c/Images/PersonalizedContentAreaRulesetContents31-300x90-1701471.jpg</imageurl></item><item><mid>36342</mid><merchantname>Buy.com</merchantname><linkid>246616304</linkid><createdon>2013-07-06/19:57:35</createdon><sku>246616304</sku><productname> Lenovo ThinkPad X220 42904E1 12.5 LED Notebook - Intel - Core i5 2.6GHz - Black - 4 GB RAM - 320 GB HDD - Genuine Windows 7 Professional 64-bit - 1366 x 768 Display - Bluetooth </productname><category><primary> Computers~~Computer Systems </primary><secondary> </secondary></category><price currency="USD">712.32</price><upccode>00887619743586</upccode><description><short>BRILLIANT BUSINESS LAPTOPS. Rock-solid reliability. Blazing-fast performance. Clever manageability tools. We pack a lot of intelligent features into every ThinkPad laptop and tablet so you get more out. More productivity, more cost savings, more IT headache-busting. That's why a ThinkPad investment isn't just smart. It's pure genius.</short><long>BRILLIANT BUSINESS LAPTOPS. Rock-solid reliability. Blazing-fast performance. Clever manageability tools. We pack a lot of intelligent features into every ThinkPad laptop and tablet so you get more out. More productivity, more cost savings, more IT headache-busting. That's why a ThinkPad investment isn't just smart. It's pure genius.</long></description><saleprice currency="USD">712.32</saleprice><keywords/><linkurl>http://affiliate.rakuten.com/link?id=yourid&amp;offerid=272843.246616304&amp;type=15&amp;murl=http%3A%2F%2Ftechnology-galaxy.store.buy.com%2Fp%2Flenovo-thinkpad-x220-42904e1-12-5-led-notebook-intel-core-i5-2-6ghz%2F246616304.html</linkurl><imageurl>http://img.rakuten.com/PIC/39586835/0/1/250/39586835.jpg</imageurl></item></result>
182
+ XML
183
+ xml_response_3 = <<-XML
184
+ <?xml version="1.0" encoding="UTF-8"?>
185
+ <result><TotalMatches>7</TotalMatches><TotalPages>3</TotalPages><PageNumber>3</PageNumber><item><mid>35825</mid><merchantname>DinoDirect China Ltd</merchantname><linkid>1221542</linkid><createdon>2012-10-26/10:25:50</createdon><sku>A0295000MA</sku><productname> 10.2-inch WIN7 Intel Atom 1.8GHz D2500 CPU 130MP Camera DDR3 RAM 2GB 160GB 1024*600 Microphone Notebook </productname><category><primary> Computers &amp; Networking </primary><secondary> PC Laptops &amp; Netbooks ~~ Netbooks </secondary></category><price currency="USD">232.99</price><upccode/><description><short>10.2-inch WIN7 Intel Atom 1.8GHz D2500 CPU 130MP Camera DDR3 RAM 2GB 160GB 1024*600 Microphone Notebook allows users to easily view documents and WebPages.Built-in Windows 7 system and 1.8GHz D2500 CPU make the netbook laptop running fast and stable.It is ideal for business people on the go, students, children and home users. You can surf the internet, send emails, instant messaging, and study, and compose documents or other things with this 320GB notebook. What's more, the 2GB laptop adopts 1.8 GHz D2500 CPU to ensure the its running speed. Besides, the 160GB notebook is lightweight and compact which easily fits in a book bag or briefcase. High resolution 1024*600 laptop that you can enjoy the visual feast.</short><long/></description><saleprice currency="USD">232.99</saleprice><keywords/><linkurl>http://click.linksynergy.com/link?id=yourid&amp;offerid=265182.1221542&amp;type=15&amp;murl=http%3A%2F%2Fus.dinodirect.com%2Fnotebook-laptop-d2500-cpu-2gb-hdd-320gb-netbook-windows-7-notebook-ultrathin-laptop.html%3Fvn%3DRGlub2RpcmVjdEZ1Y2s%26AFFID%3D41</linkurl><imageurl>http://p.lefux.com/61/20120903/A0295000MA/notebook-laptop-d2500-cpu-2gb-hdd-320gb-netbook-windows-7-no-4610708-big.jpg</imageurl></item><item><mid>2149</mid><merchantname>Wal-Mart.com USA, LLC</merchantname><linkid>26002180</linkid><createdon>2013-08-04/03:41:45</createdon><sku>0088411612032</sku><productname> Dell Fire Red 15.6" Touchscreen Inspiron 15R Laptop PC with Intel Core i3-3227U Processor, 6GB Memory, 500GB Hard Drive and Windows 8 Home </productname><category><primary> Computers~~ </primary><secondary> Electronics </secondary></category><price currency="USD">598</price><upccode>00884116120322</upccode><description><short>The Dell 15.6" Inspiron 15R Laptop PC features 6GB DDR3 SDRAM system memory to give you the power to handle most power-hungry applications and tons of multimedia work.</short><long>Dell 15.6" Inspiron 15R Laptop PC: Key Features and Benefits: Intel Core i3-3227U processor 1.9GHz, 3MB Cache 6GB DDR3 SDRAM system memory Gives you the power to handle most power-hungry applications and tons of multimedia work 500GB SATA hard drive Store 333,000 photos, 142,000 songs or 263 hours of HD video and more DVD+/-RW Drive Watch movies, and read and write CDs and DVDs in multiple formats Integrated 10/100 Fast Ethernet, Wireless-N Connect to a broadband modem with wired Ethernet or wirelessly connect to a WiFi signal or hotspot with the 802.11n connection built into your PC 15.6" HD widescreen touch display with webcam Integrated Intel HD Graphics with HDMI capabilities Additional Features: 8-in-1 memory card reader 2 x USB 3.0 ports, 2 x USB 2.0 ports, 1 x RJ-45 Ethernet port, 1 x HDMI port 6-cell lithium-ion battery 5.12 lbs, 10.2" x 14.8" x 1.23" Software: Genuine Microsoft Windows 8 Home Microsoft Office Trial and Pocket Cloud Companion McAfee LiveSafe Support and Warranty: 1-year limited hardware warranty; 24/7 technical assistance available online or toll-free by phone Restore discs are not included (unless specified by supplier). We recommend you use the installed software to create your own restore and backup DVD the first week you use the computer. What's In The Box: Power cord Dell laptop Quick Start Guide To see the manufacturer's specifications for this product, click here . To see a list of our PC Accessories, click here . Trade in your used computer and electronics for more cash to spend at Walmart. Good for your wallet and the environment - click here .</long></description><saleprice currency="USD">598</saleprice><keywords/><linkurl>http://linksynergy.walmart.com/link?id=yourid&amp;offerid=223073.26002180&amp;type=15&amp;murl=http%3A%2F%2Fwww.walmart.com%2Fip%2FDell-Fire-Red-15.6-Inspiron-15R-Laptop-PC-with-Intel-Core-i3-3227U-Processor-Touchscreen-6GB-Memory-500GB-Hard-Drive-and-Windows-8-Home%2F26002180%3Fsourceid%3D0100000012230215302434</linkurl><imageurl>http://i.walmartimages.com/i/p/00/88/41/16/12/0088411612032_Color_Red_SW_500X500.jpg</imageurl></item></result>
186
+ XML
187
+ stub_request(
188
+ :get,
189
+ "http://productsearch.linksynergy.com/productsearch?keyword=#{keyword}&max=3&token=#{token}"
190
+ ).
191
+ to_return(
192
+ status: 200,
193
+ body: xml_response_1,
194
+ headers: { "Content-type" => "text/xml; charset=UTF-8" }
195
+ )
196
+ stub_request(
197
+ :get,
198
+ "http://productsearch.linksynergy.com/productsearch?keyword=#{keyword}&max=3&pagenumber=2&token=#{token}"
199
+ ).
200
+ to_return(
201
+ status: 200,
202
+ body: xml_response_2,
203
+ headers: { "Content-type" => "text/xml; charset=UTF-8" }
204
+ )
205
+ stub_request(
206
+ :get,
207
+ "http://productsearch.linksynergy.com/productsearch?keyword=#{keyword}&max=3&pagenumber=3&token=#{token}"
208
+ ).
209
+ to_return(
210
+ status: 200,
211
+ body: xml_response_3,
212
+ headers: { "Content-type" => "text/xml; charset=UTF-8" }
213
+ )
214
+
215
+ data = LinkshareAPI.product_search(options).all
216
+ assert_equal 8, data.count
217
+ assert_equal "250014339", data.first.sku
218
+ assert_equal "http://i.walmartimages.com/i/p/00/88/41/16/12/0088411612032_Color_Red_SW_500X500.jpg", data.last.imageurl
219
+ end
220
+
221
+ private
222
+
223
+ def token
224
+ "abcdef"
225
+ end
65
226
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkshare_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-03 00:00:00.000000000 Z
12
+ date: 2013-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: addressable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.5
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: httparty
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -27,6 +43,22 @@ dependencies:
27
43
  - - ~>
28
44
  - !ruby/object:Gem::Version
29
45
  version: 0.11.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: recursive-open-struct
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.4.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.3
30
62
  - !ruby/object:Gem::Dependency
31
63
  name: bundler
32
64
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +147,7 @@ extensions: []
115
147
  extra_rdoc_files: []
116
148
  files:
117
149
  - .gitignore
150
+ - .travis.yml
118
151
  - Gemfile
119
152
  - Guardfile
120
153
  - LICENSE.txt
@@ -126,6 +159,8 @@ files:
126
159
  - lib/linkshare_api/errors/error.rb
127
160
  - lib/linkshare_api/errors/invalid_request_error.rb
128
161
  - lib/linkshare_api/link_generator.rb
162
+ - lib/linkshare_api/product_search.rb
163
+ - lib/linkshare_api/response.rb
129
164
  - lib/linkshare_api/version.rb
130
165
  - linkshare_api.gemspec
131
166
  - test/linkshare_api_test.rb