Class: ShopifyAPI::ApiVersion
- Inherits:
-
Object
- Object
- ShopifyAPI::ApiVersion
show all
- Includes:
- Comparable
- Defined in:
- lib/shopify_api/api_version.rb
Defined Under Namespace
Classes: ApiVersionNotSetError, NullVersion, UnknownVersion
Constant Summary
collapse
- UNSTABLE_HANDLE =
'unstable'
- HANDLE_FORMAT =
/((\d{4}-\d{2})|#{UNSTABLE_HANDLE})/.freeze
- UNSTABLE_AS_DATE =
Time.utc(3000, 1, 1)
- API_PREFIX =
'/admin/api/'
- LOOKUP_MODES =
[:raise_on_unknown, :define_on_unknown].freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ ApiVersion
Returns a new instance of ApiVersion.
106
107
108
109
110
111
112
113
|
# File 'lib/shopify_api/api_version.rb', line 106
def initialize(attributes)
attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
@handle = attributes[:handle].to_s
@display_name = attributes.fetch(:display_name, attributes[:handle].to_s)
@supported = attributes.fetch(:supported, false)
@latest_supported = attributes.fetch(:latest_supported, false)
@verified = attributes.fetch(:verified, false)
end
|
Class Attribute Details
.versions ⇒ Object
Returns the value of attribute versions
15
16
17
|
# File 'lib/shopify_api/api_version.rb', line 15
def versions
@versions
end
|
Instance Attribute Details
#display_name ⇒ Object
Returns the value of attribute display_name
104
105
106
|
# File 'lib/shopify_api/api_version.rb', line 104
def display_name
@display_name
end
|
#handle ⇒ Object
Returns the value of attribute handle
104
105
106
|
# File 'lib/shopify_api/api_version.rb', line 104
def handle
@handle
end
|
#latest_supported ⇒ Object
Returns the value of attribute latest_supported
104
105
106
|
# File 'lib/shopify_api/api_version.rb', line 104
def latest_supported
@latest_supported
end
|
#supported ⇒ Object
Returns the value of attribute supported
104
105
106
|
# File 'lib/shopify_api/api_version.rb', line 104
def supported
@supported
end
|
#verified ⇒ Object
Returns the value of attribute verified
104
105
106
|
# File 'lib/shopify_api/api_version.rb', line 104
def verified
@verified
end
|
Class Method Details
.add_to_known_versions(version) ⇒ Object
63
64
65
|
# File 'lib/shopify_api/api_version.rb', line 63
def add_to_known_versions(version)
@versions[version.handle] = version
end
|
.clear_defined_versions ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/shopify_api/api_version.rb', line 71
def clear_defined_versions
warn(
'[DEPRECATED] ShopifyAPI::ApiVersion.clear_defined_versions is deprecated and will be ' \
'removed in a future version. Use `clear_known_versions` instead.'
)
clear_known_versions
end
|
.clear_known_versions ⇒ Object
67
68
69
|
# File 'lib/shopify_api/api_version.rb', line 67
def clear_known_versions
@versions = {}
end
|
.coerce_to_version(version_or_handle) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/shopify_api/api_version.rb', line 41
def coerce_to_version(version_or_handle)
warn(
'[DEPRECATED] ShopifyAPI::ApiVersion.coerce_to_version be removed in a future version. ' \
'Use `find_version` instead.'
)
find_version(version_or_handle)
end
|
.define_known_versions ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/shopify_api/api_version.rb', line 55
def define_known_versions
warn(
'[DEPRECATED] ShopifyAPI::ApiVersion.define_known_versions is deprecated and will be ' \
'removed in a future version. Use `fetch_known_versions` instead.'
)
fetch_known_versions
end
|
.fetch_known_versions ⇒ Object
49
50
51
52
53
|
# File 'lib/shopify_api/api_version.rb', line 49
def fetch_known_versions
@versions = Meta.admin_versions.map do |version|
[version.handle, ApiVersion.new(version.attributes.merge(verified: version.persisted?))]
end.to_h
end
|
.find_version(version_or_handle) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/shopify_api/api_version.rb', line 27
def find_version(version_or_handle)
raise ArgumentError, "NullVersion is not a valid version or version handle." if version_or_handle == NullVersion
return version_or_handle if version_or_handle.is_a?(ApiVersion)
handle = version_or_handle.to_s
@versions ||= {}
@versions.fetch(handle) do
if @version_lookup_mode == :raise_on_unknown
raise UnknownVersion, unknown_version_error_message(handle)
else
add_to_known_versions(ApiVersion.new(handle: handle))
end
end
end
|
.latest_stable_version ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/shopify_api/api_version.rb', line 79
def latest_stable_version
warn(
'[DEPRECATED] ShopifyAPI::ApiVersion.latest_stable_version is deprecated and will be ' \
'removed in a future version.'
)
versions.values.find(&:latest_supported?)
end
|
.version_lookup_mode ⇒ Object
17
18
19
|
# File 'lib/shopify_api/api_version.rb', line 17
def version_lookup_mode
@version_lookup_mode ||= :define_on_unknown
end
|
.version_lookup_mode=(mode) ⇒ Object
21
22
23
24
25
|
# File 'lib/shopify_api/api_version.rb', line 21
def version_lookup_mode=(mode)
raise ArgumentError, "Mode must be one of #{LOOKUP_MODES}" unless LOOKUP_MODES.include?(mode)
sanitize_known_versions if mode == :raise_on_unknown
@version_lookup_mode = mode
end
|
Instance Method Details
#<=>(other) ⇒ Object
131
132
133
|
# File 'lib/shopify_api/api_version.rb', line 131
def <=>(other)
handle_as_date <=> other.handle_as_date
end
|
#==(other) ⇒ Object
135
136
137
|
# File 'lib/shopify_api/api_version.rb', line 135
def ==(other)
other.class == self.class && handle == other.handle
end
|
#construct_api_path(path) ⇒ Object
143
144
145
|
# File 'lib/shopify_api/api_version.rb', line 143
def construct_api_path(path)
"#{API_PREFIX}#{handle}/#{path}"
end
|
#construct_graphql_path ⇒ Object
147
148
149
|
# File 'lib/shopify_api/api_version.rb', line 147
def construct_graphql_path
construct_api_path('graphql.json')
end
|
#handle_as_date ⇒ Object
171
172
173
174
175
|
# File 'lib/shopify_api/api_version.rb', line 171
def handle_as_date
return UNSTABLE_AS_DATE if unstable?
year, month, day = handle.split('-')
Time.utc(year, month, day)
end
|
#hash ⇒ Object
139
140
141
|
# File 'lib/shopify_api/api_version.rb', line 139
def hash
handle.hash
end
|
#latest_supported? ⇒ Boolean
119
120
121
|
# File 'lib/shopify_api/api_version.rb', line 119
def latest_supported?
latest_supported
end
|
#name ⇒ Object
151
152
153
154
155
156
157
|
# File 'lib/shopify_api/api_version.rb', line 151
def name
warn(
'[DEPRECATED] ShopifyAPI::ApiVersion#name is deprecated and will be removed in a future version. ' \
'Use `handle` instead.'
)
handle
end
|
#stable? ⇒ Boolean
159
160
161
162
163
164
165
|
# File 'lib/shopify_api/api_version.rb', line 159
def stable?
warn(
'[DEPRECATED] ShopifyAPI::ApiVersion#stable? is deprecated and will be removed in a future version. ' \
'Use `supported?` instead.'
)
supported?
end
|
#supported? ⇒ Boolean
123
124
125
|
# File 'lib/shopify_api/api_version.rb', line 123
def supported?
supported
end
|
#to_s ⇒ Object
115
116
117
|
# File 'lib/shopify_api/api_version.rb', line 115
def to_s
handle
end
|
#unstable? ⇒ Boolean
167
168
169
|
# File 'lib/shopify_api/api_version.rb', line 167
def unstable?
handle == UNSTABLE_HANDLE
end
|
#verified? ⇒ Boolean
127
128
129
|
# File 'lib/shopify_api/api_version.rb', line 127
def verified?
verified
end
|