ebay-finding-api 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 9bfcc47fce886638f162cf550cd97ba2b60ebbbceb9cec12ca1c0c5bb10e23a8
4
- data.tar.gz: c4dc66eb1789960aa4ce1290b5c37223fa1023ca3410edb890180c9ed9b9fce6
3
+ metadata.gz: 138cd0fdefa75ca5ed2505554c22090351a6564a97ace1174011438d85b1b8d9
4
+ data.tar.gz: 51ac371b1fcc262f8b1b8ad66ac8dbcb26c2d45e635dd1e091f4badf81a81e80
5
5
  SHA512:
6
- metadata.gz: cfd7a820e6ff161c9c9776dfa36b0efc55d13fadbfaaa7796372c9c24a0d7b81c66908443d20984b0825a3a08923abb1fafa3701dbf4b806870769164e3f9a03
7
- data.tar.gz: 32cd9887030688bf08194f2e9853ad90b426019bfc4635c05a28cd852ed510edbc675b3c9b3be9523681cd651ad425fbaa9ba908271f1c936f2a1064c39220c1
6
+ metadata.gz: ae88581f2067bb13e4d2e7ded6fcfec7902ebc1a26eb0010a4996ab1ab7a9fe4b53155727ad04a98017d25974976354c8d2b8e51656f28430081aec58faccc62
7
+ data.tar.gz: 12fb3cbe62c5272951104a588c1756b3bf06256abb9f688f33877fa7651262ec9f8008cf8952b30d4465ac5f7767d2b47d7507d1e96daacb1076076210d73f20
@@ -11,3 +11,4 @@ end
11
11
  require "ebay/finding/api/version"
12
12
  require "ebay/finding/api/client"
13
13
  require "ebay/finding/api/response"
14
+ require "ebay/finding/api/error"
@@ -2,19 +2,33 @@ module Ebay::Finding::Api
2
2
  PRODUCTION_ENDPOINT = "https://svcs.ebay.com"
3
3
  SANDBOX_ENDPOINT = "https://svcs.sandbox.ebay.com"
4
4
  SERVICE_VERSION = "1.13.0"
5
+ PRODUCT_TYPES = %w(ISBN UPC EAN ReferenceID)
5
6
 
6
7
  class Client
7
8
  def initialize(app_id, sandbox = true)
8
9
  @app_id = app_id
9
10
  @sandbox = sandbox
11
+ @base_options = { "SECURITY-APPNAME" => @app_id, "SERVICE-VERSION" => SERVICE_VERSION, "REST-PAYLOAD" => "TRUE",
12
+ "RESPONSE-DATA-FORMAT" => "JSON" }
10
13
  end
11
14
 
12
15
  def find_items_by_keywords(keyword)
13
16
  operation_name = "findItemsByKeywords"
14
- options = { "OPERATION-NAME" => operation_name, "SERVICE-VERSION" => SERVICE_VERSION, "REST-PAYLOAD" => "TRUE",
15
- "SECURITY-APPNAME" => @app_id, "RESPONSE-DATA-FORMAT" => "JSON", "keywords" => keyword }
17
+ options = @base_options.merge("OPERATION-NAME" => operation_name, "keywords" => keyword)
16
18
 
17
- Response.new(operation_name, connection.get("/ervices/search/FindingService/v1", options))
19
+ Response.new(operation_name, connection.get("/services/search/FindingService/v1", options))
20
+ end
21
+
22
+ def find_items_by_product(type, product_id)
23
+ operation_name = "findItemsByProduct"
24
+
25
+ unless PRODUCT_TYPES.include? type
26
+ raise ArgumentError.new("You need to pass string 'ISBN', 'UPC', 'EAN' or 'ReferenceID' to first argument")
27
+ end
28
+ options = @base_options.merge("OPERATION-NAME" => operation_name, "productId.@type" => type,
29
+ "productId" => product_id)
30
+
31
+ Response.new(operation_name, connection.get("/services/search/FindingService/v1", options))
18
32
  end
19
33
 
20
34
  private
@@ -0,0 +1,7 @@
1
+ module Ebay::Finding::Api
2
+ class Error < StandardError
3
+ end
4
+
5
+ class ArgumentError < Error
6
+ end
7
+ end
@@ -10,7 +10,11 @@ module Ebay::Finding::Api
10
10
  def items
11
11
  return [] unless success?
12
12
 
13
- @items ||= JSON.parse(@response.body)["#{@key_name}Response"].first["searchResult"]
13
+ result = JSON.parse(@response.body)["#{@key_name}Response"].first["searchResult"].first
14
+
15
+ return [] if result["@count"] === "0"
16
+
17
+ @items ||= result["item"]
14
18
  end
15
19
 
16
20
  def success?
@@ -1,7 +1,7 @@
1
1
  module Ebay
2
2
  module Finding
3
3
  module Api
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebay-finding-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - camelmasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-13 00:00:00.000000000 Z
11
+ date: 2018-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -85,6 +85,7 @@ files:
85
85
  - ebay-finding-api.gemspec
86
86
  - lib/ebay/finding/api.rb
87
87
  - lib/ebay/finding/api/client.rb
88
+ - lib/ebay/finding/api/error.rb
88
89
  - lib/ebay/finding/api/response.rb
89
90
  - lib/ebay/finding/api/version.rb
90
91
  homepage: https://github.com/camelmasa/ebay-finding-api