rakuten_product_api 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -16
- data/README.md +14 -14
- data/lib/rakuten_product_api/authenticate.rb +32 -40
- data/lib/rakuten_product_api/client.rb +16 -22
- data/lib/rakuten_product_api/version.rb +1 -1
- data/lib/rakuten_product_api.rb +6 -11
- data/rakuten_product_api.gemspec +1 -2
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b9cbdd2339703bb57bc2d4eed267caacb9f8102153265ac00252d63a2fc7ea
|
4
|
+
data.tar.gz: f07396647cca6325ed7e87a72c1303f20f448b72380a263625527842fc4fdc94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdb8b95db0a4e09db5e89fb403aee90ab5a4038aec7ffed5da60ba967d9009f1bfaec25096317d5968d83bb2f8ba1aceb9bd0643d130827bff2bb06948552a99
|
7
|
+
data.tar.gz: 75c2e83b5990933636a2f22dde9d246f9cee997095a28723d94bbe60fc8b1e62d97f2e8d10fea563256f3e44bfa10de792dd1987b52c4220cf7ca0f442e2c4f2
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,43 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rakuten_product_api (0.
|
5
|
-
nokogiri (
|
4
|
+
rakuten_product_api (0.5.0)
|
5
|
+
nokogiri (>= 1.13.6)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
11
|
byebug (11.1.3)
|
12
|
-
minitest (5.
|
13
|
-
nokogiri (1.
|
12
|
+
minitest (5.15.0)
|
13
|
+
nokogiri (1.13.6-arm64-darwin)
|
14
14
|
racc (~> 1.4)
|
15
|
-
parallel (1.
|
16
|
-
parser (3.
|
15
|
+
parallel (1.22.1)
|
16
|
+
parser (3.1.2.0)
|
17
17
|
ast (~> 2.4.1)
|
18
|
-
racc (1.
|
19
|
-
rainbow (3.
|
18
|
+
racc (1.6.0)
|
19
|
+
rainbow (3.1.1)
|
20
20
|
rake (13.0.6)
|
21
|
-
regexp_parser (2.
|
21
|
+
regexp_parser (2.4.0)
|
22
22
|
rexml (3.2.5)
|
23
|
-
rubocop (1.
|
23
|
+
rubocop (1.29.1)
|
24
24
|
parallel (~> 1.10)
|
25
|
-
parser (>= 3.
|
25
|
+
parser (>= 3.1.0.0)
|
26
26
|
rainbow (>= 2.2.2, < 4.0)
|
27
27
|
regexp_parser (>= 1.8, < 3.0)
|
28
|
-
rexml
|
29
|
-
rubocop-ast (>= 1.
|
28
|
+
rexml (>= 3.2.5, < 4.0)
|
29
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
30
30
|
ruby-progressbar (~> 1.7)
|
31
31
|
unicode-display_width (>= 1.4.0, < 3.0)
|
32
|
-
rubocop-ast (1.
|
33
|
-
parser (>= 3.
|
32
|
+
rubocop-ast (1.18.0)
|
33
|
+
parser (>= 3.1.1.0)
|
34
34
|
ruby-progressbar (1.11.0)
|
35
35
|
unicode-display_width (2.1.0)
|
36
36
|
|
37
37
|
PLATFORMS
|
38
|
+
arm64-darwin-21
|
38
39
|
x86_64-darwin-20
|
40
|
+
x86_64-linux
|
39
41
|
|
40
42
|
DEPENDENCIES
|
41
43
|
byebug (~> 11)
|
@@ -45,4 +47,4 @@ DEPENDENCIES
|
|
45
47
|
rubocop (~> 1.7)
|
46
48
|
|
47
49
|
BUNDLED WITH
|
48
|
-
2.
|
50
|
+
2.3.10
|
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
|
-
- [
|
9
|
-
- [
|
10
|
-
- [API Keys](https://developers.
|
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
|
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.
|
36
|
-
config.
|
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.
|
48
|
-
=> "your-
|
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 `
|
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 `
|
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.
|
62
|
-
=> "
|
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, :
|
10
|
+
attr_accessor :sid, :endpoint, :access_token, :access_token_expires_at, :refresh_token
|
11
11
|
|
12
|
-
def initialize(sid: RakutenProductApi.sid,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
@
|
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
|
35
|
-
Base64.strict_encode64("#{@
|
32
|
+
def token_key
|
33
|
+
Base64.strict_encode64("#{@client_id}:#{@client_secret}").strip
|
36
34
|
end
|
37
35
|
|
38
|
-
def
|
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
|
-
@
|
41
|
+
@access_token_expires_at = Time.now.to_i + @expires_in
|
47
42
|
end
|
48
43
|
|
49
|
-
def
|
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
|
-
@
|
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(
|
73
|
-
uri = URI(
|
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"] = "
|
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 @
|
85
|
-
#
|
86
|
-
|
87
|
-
elsif Time.now.to_i > @
|
88
|
-
#
|
89
|
-
|
90
|
-
elsif Time.now.to_i > (@
|
91
|
-
#
|
92
|
-
|
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, :
|
13
|
+
attr_accessor :sid, :username, :password, :authenticate
|
14
14
|
|
15
|
-
def initialize(sid:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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(
|
39
|
-
|
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
|
-
|
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)
|
data/lib/rakuten_product_api.rb
CHANGED
@@ -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.
|
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
|
data/rakuten_product_api.gemspec
CHANGED
@@ -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.
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rakuten_product_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
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:
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
19
|
+
version: '1.13'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.13.6
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
29
|
+
version: '1.13'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.13.6
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: byebug
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
90
|
- !ruby/object:Gem::Version
|
85
91
|
version: '0'
|
86
92
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
93
|
+
rubygems_version: 3.3.7
|
88
94
|
signing_key:
|
89
95
|
specification_version: 4
|
90
96
|
summary: Client for Rakutenmarketing.com.
|