betsy 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 343e99ec22018a9e3a9213d0347a41c7e2467ae065663d0949f911569e9e18ee
4
- data.tar.gz: d30007fc1dd8c093db8e3281b438e21431cdce28ec2da31298d331c69c3811af
3
+ metadata.gz: be84657637faf15358471454761e8f48181ce8907741f64120ce17837d777119
4
+ data.tar.gz: f7b0948911a4271e09423591f7bd55e6be04612c5502c32bc2cb9d2713bd279f
5
5
  SHA512:
6
- metadata.gz: 63eefeee0bba2edab434f1b702ab82d1fd694611c73d72c21ab8235cf24504a9649fc82297ce81daafde98cbfc130a6ce518d907d37add81f83475e6cff7e708
7
- data.tar.gz: 0f27a68eb7ed1682c10c2440f5e2f5be421f3491e1fd5137ba44918884a7cc4a0e21bf41f8ea96876803ee02cf435f835e32ec438174e57ce1bff5af7ac9c603
6
+ metadata.gz: e34859ed8deb1e858c2284c2a0691d4a5ddaa09e6efa2b1a867f58956cb73456161285356603500ecd287d15455667e82422f77ec01c2aa2138296a61327510e
7
+ data.tar.gz: 75120021566c48ece0adf0ca7abf44b61efb9903d77a950fcac75383eb9ad2a985a8a496a2f50665f18fdecbefc9611ce3efb81a497bf8114015ac04438863cc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2026-05-14
4
+
5
+ ### Breaking changes
6
+
7
+ - The account model (default `EtsyAccount`) must now implement a `token_expired?` instance method. If you ran the install generator in v0.2.x, you need to add this method manually. See the [migration guide](#migrating-from-v02x-to-v03x) in the README.
8
+
9
+ ### Changed
10
+
11
+ - Token expiration checking now delegates to `token_expired?` on the account model instead of using inline logic in the gem
12
+ - Replaced Faraday with Ruby's stdlib `Net::HTTP`, removing the only external runtime dependency
13
+ - Declared `activesupport` as an explicit runtime dependency (was previously undeclared)
14
+
15
+ ### Fixed
16
+
17
+ - Fixed `TypeError` crash in `check_token_expiration` when `expires_in` or `last_token_refresh` is nil
18
+ - Failed token refresh responses no longer save nil credentials back to the account
19
+
3
20
  ## [0.2.0] - 2021-05-04
4
21
 
5
22
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- betsy (0.2.0)
5
- faraday (>= 0.10)
4
+ betsy (0.3.0)
5
+ activesupport (>= 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -83,8 +83,6 @@ GEM
83
83
  diff-lcs (1.4.4)
84
84
  docile (1.4.0)
85
85
  erubi (1.10.0)
86
- faraday (0.17.6)
87
- multipart-post (>= 1.2, < 3)
88
86
  globalid (0.5.2)
89
87
  activesupport (>= 5.0)
90
88
  hashdiff (1.0.1)
@@ -100,9 +98,8 @@ GEM
100
98
  method_source (1.0.0)
101
99
  mini_mime (1.1.0)
102
100
  minitest (5.14.4)
103
- multipart-post (2.3.0)
104
101
  nio4r (2.5.8)
105
- nokogiri (1.12.2-x86_64-linux)
102
+ nokogiri (1.19.3-x86_64-linux-gnu)
106
103
  racc (~> 1.4)
107
104
  parallel (1.20.1)
108
105
  parser (3.0.2.0)
data/README.md CHANGED
@@ -66,6 +66,32 @@ Betsy::UserAddress.get_user_addresses(etsy_account: EtsyAccount.first)
66
66
 
67
67
  By default, Betsy handles the refreshing of authentication tokens for you.
68
68
 
69
+ ## Migrating from v0.2.x to v0.3.x
70
+
71
+ ### Account model requires `token_expired?`
72
+
73
+ In v0.3.0, the token expiration check was moved out of the gem and into your account model. You need to add a `token_expired?` method to your `EtsyAccount` model (or whatever model you configured via `Betsy.account_model`):
74
+
75
+ ```ruby
76
+ class EtsyAccount < ApplicationRecord
77
+ def token_expired?
78
+ last_token_refresh.nil? || expires_in.nil? || last_token_refresh + expires_in <= DateTime.now
79
+ end
80
+ end
81
+ ```
82
+
83
+ This gives you full control over the expiration logic. For example, you could add a buffer to refresh tokens early:
84
+
85
+ ```ruby
86
+ def token_expired?
87
+ last_token_refresh.nil? || expires_in.nil? || last_token_refresh + expires_in - 5.minutes <= DateTime.now
88
+ end
89
+ ```
90
+
91
+ ### Faraday removed
92
+
93
+ Betsy no longer depends on Faraday. It uses Ruby's built-in `Net::HTTP` instead. If your app was relying on Betsy to pull in Faraday, you'll need to add it to your own Gemfile.
94
+
69
95
  ## License
70
96
 
71
97
  The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/betsy.gemspec CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency("webmock", "~> 3.13.0")
38
38
  spec.add_development_dependency("coveralls")
39
39
 
40
- spec.add_dependency("faraday", ">= 0.10")
40
+ spec.add_dependency("activesupport", ">= 5.0")
41
41
 
42
42
  # For more information and examples about making a new gem, checkout our
43
43
  # guide at: https://bundler.io/guides/creating_gem.html
data/lib/betsy/model.rb CHANGED
@@ -9,28 +9,52 @@ module Betsy
9
9
  end
10
10
  end
11
11
 
12
+ REQUEST_CLASSES = {
13
+ get: Net::HTTP::Get,
14
+ post: Net::HTTP::Post,
15
+ put: Net::HTTP::Put,
16
+ patch: Net::HTTP::Patch,
17
+ delete: Net::HTTP::Delete
18
+ }.freeze
19
+
12
20
  def make_request(request_type, endpoint, options = {})
13
21
  check_token_expiration(options[:etsy_account]) if options[:etsy_account]
14
22
  headers = access_credentials(options[:etsy_account])
15
23
  options.delete(:etsy_account)
16
24
 
25
+ uri = URI("#{BASE_ETSY_API_URL}#{endpoint}")
26
+
17
27
  if [:post, :put, :patch].include?(request_type)
18
28
  headers = headers.reverse_merge(content_type: "application/json")
19
- options = options.to_json
29
+ request = REQUEST_CLASSES[request_type].new(uri)
30
+ request.body = options.to_json
31
+ else
32
+ uri.query = URI.encode_www_form(options) if options.any?
33
+ request = REQUEST_CLASSES[request_type].new(uri)
34
+ end
35
+
36
+ headers.each { |key, value| request[key.to_s] = value }
37
+
38
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
39
+ http.request(request)
20
40
  end
21
41
 
22
- response = Faraday.send(request_type, "#{BASE_ETSY_API_URL}#{endpoint}", options, headers)
23
42
  handle_response(response)
24
43
  end
25
44
 
26
45
  def check_token_expiration(etsy_account)
27
- if etsy_account.last_token_refresh + etsy_account.expires_in <= DateTime.now
46
+ if etsy_account.token_expired?
28
47
  options = {
29
48
  grant_type: "refresh_token",
30
49
  refresh_token: etsy_account.refresh_token,
31
50
  client_id: Betsy.api_key
32
51
  }
33
- response = JSON.parse(Faraday.post("https://api.etsy.com/v3/public/oauth/token", options).body)
52
+ response = JSON.parse(Net::HTTP.post_form(URI("https://api.etsy.com/v3/public/oauth/token"), options).body)
53
+
54
+ if response["access_token"].nil?
55
+ raise "Etsy token refresh failed: #{response}"
56
+ end
57
+
34
58
  etsy_account.access_token = response["access_token"]
35
59
  etsy_account.expires_in = response["expires_in"]
36
60
  etsy_account.refresh_token = response["refresh_token"]
@@ -46,12 +70,12 @@ module Betsy
46
70
  end
47
71
 
48
72
  def handle_response(response)
49
- if response.status == 200
73
+ if response.code.to_i == 200
50
74
  return nil if response.body.empty?
51
75
  response = JSON.parse(response.body)
52
76
  build_objects(response)
53
77
  else
54
- Betsy::Error.new(JSON.parse(response.body).merge!("status" => response.status))
78
+ Betsy::Error.new(JSON.parse(response.body).merge!("status" => response.code.to_i))
55
79
  end
56
80
  end
57
81
 
data/lib/betsy/review.rb CHANGED
@@ -18,5 +18,9 @@ module Betsy
18
18
  def self.get_reviews_by_shop(shop_id, options = {})
19
19
  make_request(:get, "/v3/application/shops/#{shop_id}/reviews", options)
20
20
  end
21
+
22
+ def self.get_reviews_by_listing(listing_id, options = {})
23
+ make_request(:get, "/v3/application/listings/#{listing_id}/reviews", options)
24
+ end
21
25
  end
22
26
  end
@@ -52,6 +52,9 @@ module Betsy
52
52
  attribute :language
53
53
  attribute :price
54
54
  attribute :taxonomy_id
55
+ attribute :production_partners
56
+ attribute :skus
57
+ attribute :views
55
58
 
56
59
  # listing properties
57
60
  attribute :property_id
data/lib/betsy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betsy
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/betsy.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
- require "faraday"
4
+ require "net/http"
5
+ require "uri"
6
+ require "json"
5
7
 
6
8
  require_relative "betsy/version"
7
9
  require_relative "betsy/model"
@@ -95,7 +97,7 @@ module Betsy
95
97
  code: params[:code],
96
98
  code_verifier: etsy_account.code_verifier
97
99
  }
98
- response = JSON.parse(Faraday.post("https://api.etsy.com/v3/public/oauth/token", options).body)
100
+ response = JSON.parse(Net::HTTP.post_form(URI("https://api.etsy.com/v3/public/oauth/token"), options).body)
99
101
  etsy_account.access_token = response["access_token"]
100
102
  etsy_account.refresh_token = response["refresh_token"]
101
103
  etsy_account.expires_in = response["expires_in"]
@@ -1,2 +1,5 @@
1
1
  class <%= Betsy.account_model %> < ApplicationRecord
2
+ def token_expired?
3
+ last_token_refresh.nil? || expires_in.nil? || last_token_refresh + expires_in <= DateTime.now
4
+ end
2
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jace Bayless
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-02 00:00:00.000000000 Z
11
+ date: 2026-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: faraday
112
+ name: activesupport
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '0.10'
117
+ version: '5.0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '0.10'
124
+ version: '5.0'
125
125
  description: This gem allows users to simply interact with the Etsy V3 API.
126
126
  email:
127
127
  - jacebayless@gmail.com
@@ -184,7 +184,7 @@ metadata:
184
184
  homepage_uri: https://github.com/JaceBayless/betsy
185
185
  source_code_uri: https://github.com/JaceBayless/betsy
186
186
  changelog_uri: https://github.com/JaceBayless/betsy/blob/main/CHANGELOG.md
187
- post_install_message:
187
+ post_install_message:
188
188
  rdoc_options: []
189
189
  require_paths:
190
190
  - lib
@@ -199,8 +199,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  requirements: []
202
- rubygems_version: 3.2.33
203
- signing_key:
202
+ rubygems_version: 3.4.20
203
+ signing_key:
204
204
  specification_version: 4
205
205
  summary: A gem for the Etsy API V3
206
206
  test_files: []