rakuten_product_api 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 679b3d9dba92d97e14f70f3b83648d49b0508e0e9060f75e1fe7ea070760be83
4
- data.tar.gz: 988b9afe879c4c0be3c670ac036e32b6393cf9d2afaaade1806553b5f899d54c
3
+ metadata.gz: 75b9cbdd2339703bb57bc2d4eed267caacb9f8102153265ac00252d63a2fc7ea
4
+ data.tar.gz: f07396647cca6325ed7e87a72c1303f20f448b72380a263625527842fc4fdc94
5
5
  SHA512:
6
- metadata.gz: c4d91eb4f03f5c13c6d840bc2510f5f746f839fe5ac9339ab242eeec1db59bbf2a4834e63d8787018bc791b28695b57fe235f9a7366b54e55e508e1577286be7
7
- data.tar.gz: 66f8ba69dfc50802d57a9fd22a7e4db205972909112eebf0668b61a3935f69524ba1a0a8f0bc1ed48e3ce0899673bc9fe0467228c2e22e3b936a56845e21e2a8
6
+ metadata.gz: cdb8b95db0a4e09db5e89fb403aee90ab5a4038aec7ffed5da60ba967d9009f1bfaec25096317d5968d83bb2f8ba1aceb9bd0643d130827bff2bb06948552a99
7
+ data.tar.gz: 75c2e83b5990933636a2f22dde9d246f9cee997095a28723d94bbe60fc8b1e62d97f2e8d10fea563256f3e44bfa10de792dd1987b52c4220cf7ca0f442e2c4f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rakuten_product_api (0.4.1)
4
+ rakuten_product_api (0.5.0)
5
5
  nokogiri (>= 1.13.6)
6
6
 
7
7
  GEM
@@ -12,10 +12,6 @@ GEM
12
12
  minitest (5.15.0)
13
13
  nokogiri (1.13.6-arm64-darwin)
14
14
  racc (~> 1.4)
15
- nokogiri (1.13.6-x86_64-darwin)
16
- racc (~> 1.4)
17
- nokogiri (1.13.6-x86_64-linux)
18
- racc (~> 1.4)
19
15
  parallel (1.22.1)
20
16
  parser (3.1.2.0)
21
17
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -5,9 +5,9 @@ To experiment with this library, run `bin/console` for an interactive prompt.
5
5
  ## API Documentation
6
6
 
7
7
  The Rakuten Product API documentation can be found at the following links.
8
- - [API Documentation PDF](https://developers.rakutenmarketing.com/console/registry/resource/_system/governance/apimgt/applicationdata/provider/RakutenMarketing/artifacts/API_Developer_Portal-Acquiring_Your_Access_Token_Guide.pdf)
9
- - [API Overview](https://developers.rakutenmarketing.com/subscribe/)
10
- - [API Keys](https://developers.rakutenmarketing.com/subscribe/site/pages/subscriptions.jag)
8
+ - [Tryout Guide](https://developers.rakutenadvertising.com/guides/try_out_apis)
9
+ - [Product Search](https://developers.rakutenadvertising.com/guides/product_search)
10
+ - [API Keys](https://developers.rakutenadvertising.com/default/dashboard/applications/)
11
11
 
12
12
  ## Installation
13
13
 
@@ -27,15 +27,15 @@ Or install it yourself as:
27
27
 
28
28
  ## Usage
29
29
 
30
- The library can be configured with an initializer. For Rails, create the file `config/initializers/rakuten.rb`
30
+ The library comes with `bin/console` which can be used to explore the client and api. If there is a local `./config.rb` the console script will load it.
31
+
32
+ To configured the library for Rails, create an initializer file `config/initializers/rakuten.rb`
31
33
 
32
34
  ```ruby
33
35
  RakutenProductApi.configure do |config|
34
36
  config.sid = 'your-site-id'
35
- config.username = 'your-rakuten-username'
36
- config.password = 'your-rakuten-password'
37
- config.consumer_key = 'your-consumer-key'
38
- config.consumer_secret = 'your-consumer-secret'
37
+ config.client_id = 'your-client-id'
38
+ config.client_secret = 'your-client-secret'
39
39
  end
40
40
  ```
41
41
 
@@ -44,22 +44,22 @@ Once you have configured the library, you can create a client.
44
44
  ```ruby
45
45
  client = RakutenProductApi::Client.new
46
46
 
47
- client.username
48
- => "your-rakuten-username"
47
+ client.sid
48
+ => "your-site-id"
49
49
  ```
50
50
 
51
51
  This client should be threadsafe. Configuration values are local to your instance.
52
52
 
53
53
  ### Authentication
54
- This library needs to query the API to retreive an `access_token` which has an `access_expires_at` time, prior to which, the library will refresh the token
54
+ This library needs to query the API to retreive an `access_token` which has an `access_token_expires_at` time, prior to which, the library will refresh the token
55
55
 
56
- You can initialise the library with the `access_token` and `access_expires_at` values to avoid this lookup. If the `access_expires_at` is in the past, the library will fetch the value so you can safely cache this value and use it without checking it's expiry.
56
+ You can initialise the library with the `access_token` and `access_token_expires_at` values to avoid this lookup. If the `access_token_expires_at` is nil or in the past, the library will fetch the value so you can safely cache this value and use it without checking it's expiry.
57
57
 
58
58
  ```ruby
59
59
  client = RakutenProductApi::Client.new(access_token: 'abcd1234', access_expires_at: 1613362973)
60
60
 
61
- client.username
62
- => "dkam"
61
+ client.endpoint
62
+ => "https://api.linksynergy.com"
63
63
 
64
64
  client.access_token
65
65
  => "abcd1234"
@@ -7,23 +7,21 @@ require "json"
7
7
  module RakutenProductApi
8
8
  class Authenticate
9
9
  REFRESH_TOKEN_LEEWAY = 60 * 10 # Ten minutes prior to expiry we should refresh token
10
- attr_accessor :sid, :username, :password, :consumer_key, :consumer_secret, :access_token, :access_expires_at
10
+ attr_accessor :sid, :endpoint, :access_token, :access_token_expires_at, :refresh_token
11
11
 
12
- def initialize(sid: RakutenProductApi.sid,
13
- username: RakutenProductApi.username,
14
- password: RakutenProductApi.password,
15
- consumer_key: RakutenProductApi.consumer_key,
16
- consumer_secret: RakutenProductApi.consumer_secret,
17
- access_token: nil,
18
- access_expires_at: nil)
12
+ def initialize( sid: RakutenProductApi.sid,
13
+ client_id: RakutenProductApi.client_id,
14
+ client_secret: RakutenProductApi.client_secret,
15
+ endpoint: RakutenProductApi.endpoint,
16
+ access_token: nil,
17
+ access_token_expires_at: nil)
19
18
 
20
- @sid = sid
21
- @username = username
22
- @password = password
23
- @consumer_key = consumer_key
24
- @consumer_secret = consumer_secret
19
+ @sid = sid # account-id ?
25
20
  @access_token = access_token
26
- @access_expires_at = access_expires_at
21
+ @access_token_expires_at = access_token_expires_at
22
+ @client_id = client_id
23
+ @client_secret = client_secret
24
+ @endpoint = endpoint
27
25
  end
28
26
 
29
27
  def auth_header
@@ -31,30 +29,24 @@ module RakutenProductApi
31
29
  "Bearer #{@access_token}"
32
30
  end
33
31
 
34
- def request_auth_token
35
- Base64.strict_encode64("#{@consumer_key}:#{@consumer_secret}").strip
32
+ def token_key
33
+ Base64.strict_encode64("#{@client_id}:#{@client_secret}").strip
36
34
  end
37
35
 
38
- def api_request_auth
39
- res = auth_request(
40
- "https://api.rakutenmarketing.com/token",
41
- { grant_type: "password", username: @username, password: @password, scope: @sid }
42
- )
36
+ def api_request_auth_token
37
+ res = auth_request( { scope: @sid } )
43
38
 
44
39
  process_auth_response(res)
45
40
 
46
- @access_expires_at = Time.now.to_i + @expires_in
41
+ @access_token_expires_at = Time.now.to_i + @expires_in
47
42
  end
48
43
 
49
- def refresh_api_request_auth
50
- res = auth_request(
51
- "https://api.rakutenmarketing.com/token",
52
- { grant_type: "refresh_token", refresh_token: @refresh_token, scope: "Production" }
53
- )
44
+ def refresh_api_request_auth_token
45
+ res = auth_request( { refresh_token: @refresh_token, scope: @sid} )
54
46
 
55
47
  process_auth_response(res)
56
48
 
57
- @access_expires_at = Time.now.to_i + @expires_in
49
+ @access_token_expires_at = Time.now.to_i + @expires_in
58
50
  end
59
51
 
60
52
  def process_auth_response(res)
@@ -69,11 +61,11 @@ module RakutenProductApi
69
61
  end
70
62
  end
71
63
 
72
- def auth_request(url, payload)
73
- uri = URI(url)
64
+ def auth_request(payload)
65
+ uri = URI("#{@endpoint}/token")
74
66
  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
75
67
  req = Net::HTTP::Post.new(uri)
76
- req["Authorization"] = "Basic #{request_auth_token}"
68
+ req["Authorization"] = "Bearer #{token_key}"
77
69
 
78
70
  req.set_form_data(payload)
79
71
  http.request(req)
@@ -81,15 +73,15 @@ module RakutenProductApi
81
73
  end
82
74
 
83
75
  def ensure_authentication
84
- if @access_expires_at.nil?
85
- # puts "NIL: getting auth"
86
- api_request_auth
87
- elsif Time.now.to_i > @access_expires_at
88
- # puts "EXPIRED: getting auth"
89
- api_request_auth
90
- elsif Time.now.to_i > (@access_expires_at + REFRESH_TOKEN_LEEWAY)
91
- # puts "REFRESH LEEWAY: getting auth"
92
- refresh_api_request_auth
76
+ if @access_token_expires_at.nil?
77
+ #puts "NO TOKEN: getting auth token"
78
+ api_request_auth_token
79
+ elsif Time.now.to_i > @access_token_expires_at
80
+ #puts "EXPIRED TOKEN: getting auth token"
81
+ api_request_auth_token
82
+ elsif Time.now.to_i > (@access_token_expires_at - REFRESH_TOKEN_LEEWAY)
83
+ #puts "TOKEN EXPIRES WITHIN LEEWAY : refresh auth token"
84
+ refresh_api_request_auth_token
93
85
  end
94
86
  end
95
87
  end
@@ -10,38 +10,32 @@ module RakutenProductApi
10
10
  def_delegators :@authenticate, :access_token, :access_expires_at
11
11
  REFRESH_TOKEN_LEEWAY = 60 * 10 # Ten minutes prior to expiry we should refresh token
12
12
 
13
- attr_accessor :sid, :username, :password, :consumer_key, :consumer_secret, :authenticate
13
+ attr_accessor :sid, :username, :password, :authenticate
14
14
 
15
- def initialize(sid: RakutenProductApi.sid,
16
- username: RakutenProductApi.username,
17
- password: RakutenProductApi.password,
18
- consumer_key: RakutenProductApi.consumer_key,
19
- consumer_secret: RakutenProductApi.consumer_secret,
20
- access_token: nil,
21
- access_expires_at: nil)
15
+ def initialize(sid: RakutenProductApi.sid,
16
+ endpoint: RakutenProductApi.endpoint,
17
+ access_token: nil,
18
+ access_token_expires_at: nil)
19
+
20
+ @sid = sid
21
+ @endpoint = endpoint
22
22
 
23
23
  @authenticate = Authenticate.new(sid: sid,
24
- username: username,
25
- password: password,
26
- consumer_key: consumer_key,
27
- consumer_secret: consumer_secret,
28
24
  access_token: access_token,
29
- access_expires_at: access_expires_at)
25
+ access_token_expires_at: access_token_expires_at)
30
26
 
31
- @sid = sid
32
- @username = username
33
- @password = password
34
- @consumer_key = consumer_key
35
- @consumer_secret = consumer_secret
36
27
  end
37
28
 
38
- def search(keyword: nil, **options)
39
- Response.new(api_request(options.merge(keyword: keyword)))
29
+ def search(**options)
30
+ params = %i{ keyword exact one none cat language max pagenumber mid, sort, sorttype }
31
+ allowed_options = options.select {|k, v| params.include?(k)}
32
+ Response.new(api_request(options, '/productsearch/1.0'))
40
33
  end
41
34
 
42
- def api_request(payload)
35
+ def api_request(payload, path)
43
36
  params = payload.map { |k, v| "#{k}=#{v}" }.join("&")
44
- uri = URI("https://api.rakutenmarketing.com/productsearch/1.0?#{params}")
37
+
38
+ uri = URI("#{@endpoint}#{path}?#{params}")
45
39
 
46
40
  res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
47
41
  req = Net::HTTP::Get.new(uri)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RakutenProductApi
4
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -11,26 +11,21 @@ require_relative "rakuten_product_api/item"
11
11
  module RakutenProductApi
12
12
  class Error < StandardError; end
13
13
 
14
- APPLICATION_END_POINT = "https://api.rakutenmarketing.com/productsearch/1.0"
14
+ APPLICATION_END_POINT = "https://api.linksynergy.com"
15
15
 
16
16
  class << self
17
17
  attr_accessor :sid,
18
- :username,
19
- :password,
20
- :consumer_key,
21
- :consumer_secret,
22
18
  :mid,
23
19
  :sort,
24
- :sorttype
20
+ :sorttype,
21
+ :client_id,
22
+ :client_secret,
23
+ :endpoint
25
24
 
26
25
  def configure
26
+ self.endpoint = APPLICATION_END_POINT # Set a default API Endpoint
27
27
  yield self
28
- true
29
28
  end
30
29
  alias config configure
31
-
32
- def hello
33
- puts "Oh Hai"
34
- end
35
30
  end
36
31
  end
@@ -29,8 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
32
- spec.add_dependency "nokogiri", ">= 1.13.6"
33
-
32
+ spec.add_runtime_dependency 'nokogiri', '~> 1.13', '>= 1.13.6'
34
33
  spec.add_development_dependency "byebug", "~> 11"
35
34
 
36
35
  # For more information and examples about making a new gem, checkout our
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakuten_product_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Milne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-25 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 1.13.6
@@ -21,6 +24,9 @@ dependencies:
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.13'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 1.13.6