ruby-etsy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruby-etsy/calls/receipts.rb +14 -0
- data/lib/ruby-etsy/calls.rb +7 -0
- data/lib/ruby-etsy/client.rb +76 -0
- data/lib/ruby-etsy/configuration.rb +23 -0
- data/lib/ruby-etsy/version.rb +3 -0
- data/lib/ruby-etsy.rb +15 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b5c1119506f213182d14a2ad038226dd479d2a8b7bae80c550d27bbc2163b4d4
|
4
|
+
data.tar.gz: 8aaad4438e7466c828e1b45b1e96dac5866f0626bd5586c9250eece41a22b502
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bd25b9a3d23ba7aab5244556d63e032f2c8e5e9d37b37945e730878b3afd39d263bd4841b2bdceb81a2d0407726813c167cc9820976342765a86bfa255f4ce9
|
7
|
+
data.tar.gz: dc0025d447c0bca6dab1efd383271d1f06372ab9460ff5921c0ec852b1c71612b0bd230b6d04a2abc7f279089a8085df74cc9b7c69e65c86bd3e6c440444522d
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class RubyEtsy
|
2
|
+
module Calls
|
3
|
+
module Receipts
|
4
|
+
|
5
|
+
def get_receipts
|
6
|
+
client.action("/shops/#{client.shop_id}/receipts", http_method: :get)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_receipt(id)
|
10
|
+
client.action("/shops/#{client.shop_id}/receipts/#{id}", http_method: :get)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'http-parser'
|
4
|
+
|
5
|
+
class RubyEtsy
|
6
|
+
class Client
|
7
|
+
|
8
|
+
REFRESH_TOKEN_URL='https://api.etsy.com/v3/public/oauth/token'
|
9
|
+
V3_URL='https://openapi.etsy.com/v3/application'
|
10
|
+
|
11
|
+
attr_accessor :access_token, :refresh_token, :api_key, :api_secret, :shop_id
|
12
|
+
|
13
|
+
def initialize(access_token:, refresh_token:, api_key:, api_secret:, shop_id:)
|
14
|
+
RubyEtsy.configure
|
15
|
+
|
16
|
+
@access_token = access_token || RubyEtsy.config.access_token
|
17
|
+
@refresh_token = refresh_token || RubyEtsy.config.refresh_token
|
18
|
+
@api_key = api_key || RubyEtsy.config.api_key
|
19
|
+
@api_secret = api_secret || RubyEtsy.config.api_secret
|
20
|
+
@shop_id = shop_id || RubyEtsy.config.shop_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def action(url, payload: {}, http_method: :post)
|
24
|
+
headers = {
|
25
|
+
'User-Agent': "RubyEtsy client v#{RubyEtsy::VERSION})",
|
26
|
+
'x-api-key': api_key,
|
27
|
+
'Authorization': "Bearer #{access_token}"
|
28
|
+
}
|
29
|
+
|
30
|
+
response = ::RestClient::Request.execute(
|
31
|
+
method: http_method,
|
32
|
+
url: construct_url(url),
|
33
|
+
payload: payload.to_json,
|
34
|
+
headers: headers,
|
35
|
+
timeout: 5,
|
36
|
+
verify_ssl: ::OpenSSL::SSL::VERIFY_NONE
|
37
|
+
)
|
38
|
+
|
39
|
+
::HttpParser.parse(response)
|
40
|
+
rescue RestClient::Unauthorized => e
|
41
|
+
puts "RESCUED UNATHORIZED"
|
42
|
+
|
43
|
+
refresh_token
|
44
|
+
action(url, http_method: :get)
|
45
|
+
end
|
46
|
+
|
47
|
+
def refresh_token
|
48
|
+
payload = {
|
49
|
+
grant_type: :refresh_token,
|
50
|
+
refresh_token: @refresh_token,
|
51
|
+
client_id: @api_key
|
52
|
+
}
|
53
|
+
|
54
|
+
response = ::RestClient::Request.execute(
|
55
|
+
method: :post,
|
56
|
+
url: REFRESH_TOKEN_URL,
|
57
|
+
payload: payload.to_json,
|
58
|
+
headers: { content_type: :json, accept: :json },
|
59
|
+
timeout: 5,
|
60
|
+
verify_ssl: ::OpenSSL::SSL::VERIFY_NONE
|
61
|
+
)
|
62
|
+
|
63
|
+
parsed = JSON.parse(response.body)
|
64
|
+
@access_token = parsed['access_token']
|
65
|
+
@refresh_token = parsed['refresh_token']
|
66
|
+
|
67
|
+
::HttpParser.parse(response)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def construct_url(url)
|
73
|
+
"#{V3_URL}#{url}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class RubyEtsy
|
2
|
+
class << self
|
3
|
+
# Accessor for global configuration.
|
4
|
+
attr_accessor :config
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
self.config ||= Configuration.new
|
9
|
+
yield(config) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
attr_accessor :access_token, :refresh_token, :api_key, :api_secret, :shop_id
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@access_token = nil
|
17
|
+
@refresh_token = nil
|
18
|
+
@api_key = nil
|
19
|
+
@api_secret = nil
|
20
|
+
@shop_id = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/ruby-etsy.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ruby-etsy/client'
|
2
|
+
require 'ruby-etsy/calls'
|
3
|
+
require 'ruby-etsy/version'
|
4
|
+
require 'ruby-etsy/configuration'
|
5
|
+
require 'byebug'
|
6
|
+
|
7
|
+
class RubyEtsy
|
8
|
+
include Calls
|
9
|
+
|
10
|
+
attr_accessor :client
|
11
|
+
|
12
|
+
def initialize(access_token:, refresh_token:, api_key:, api_secret:, shop_id:)
|
13
|
+
@client = Client.new(access_token: access_token, refresh_token: refresh_token, api_key: api_key, api_secret: api_secret, shop_id: shop_id)
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-etsy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adem Dinarevic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: parse-http
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.1
|
55
|
+
description: Ruby client for Etsy API
|
56
|
+
email:
|
57
|
+
- ademdinarevic@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/ruby-etsy.rb
|
63
|
+
- lib/ruby-etsy/calls.rb
|
64
|
+
- lib/ruby-etsy/calls/receipts.rb
|
65
|
+
- lib/ruby-etsy/client.rb
|
66
|
+
- lib/ruby-etsy/configuration.rb
|
67
|
+
- lib/ruby-etsy/version.rb
|
68
|
+
homepage: https://github.com/ademdc/ruby-etsy
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.3'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.0.9
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Ruby client for Etsy API
|
91
|
+
test_files: []
|