shopify_url 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/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +19 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +6 -0
- data/lib/shopify_url.rb +234 -0
- data/shopify_url.gemspec +28 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9ee2f1ff5fd66a97a6785d29f8b952be8a8379e
|
4
|
+
data.tar.gz: 24d83b84b58f4c7800de88904f5508f5ab6d00c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f18349ccc562b3aaeba1f019ed8fd43d075ef8329d4235e153172e38474b020f06c91ddc7fe16a03ff2fce30af1c38e481c130cf5595be84ecd690663531125
|
7
|
+
data.tar.gz: f033e5530ec165397691a79fff833cc1ddf3c85f5a5d64dc23bcb0ecc1fe1cafcf8756676e06ed89191f88066ab64e46deb35bffe41c71fda00b90690ca806a2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.2
|
7
|
+
- 2.3
|
8
|
+
- 2.4
|
9
|
+
- 2.5
|
10
|
+
- 2.6
|
11
|
+
- 2.7
|
12
|
+
|
13
|
+
# https://docs.travis-ci.com/user/languages/ruby/#bundler-20
|
14
|
+
before_install:
|
15
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
16
|
+
- gem install bundler -v '< 2'
|
17
|
+
|
18
|
+
notifications:
|
19
|
+
email: false
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 sshaw
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Shopify URL
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/ScreenStaring/shopify_url.svg?branch=master)](https://travis-ci.org/ScreenStaring/shopify_url)
|
4
|
+
|
5
|
+
Build URLs to Shopify web pages.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Admin URLs
|
10
|
+
|
11
|
+
```rb
|
12
|
+
require "shopify_url"
|
13
|
+
|
14
|
+
url = ShopifyURL::Admin.new("shopname")
|
15
|
+
|
16
|
+
# https://shopname.myshopify.com/admin"
|
17
|
+
url.to_s
|
18
|
+
|
19
|
+
# https://shopname.myshopify.com/admin/orders
|
20
|
+
url.orders
|
21
|
+
|
22
|
+
# https://shopname.myshopify.com/admin/orders/6303508996
|
23
|
+
url.order(6303508996)
|
24
|
+
|
25
|
+
# https://shopname.myshopify.com/admin/products
|
26
|
+
url.products
|
27
|
+
|
28
|
+
# https://shopname.myshopify.com/admin/products/345323423
|
29
|
+
url.product(345323423)
|
30
|
+
|
31
|
+
# https://shopname.myshopify.com/admin/products/345323423/variants/2421342331
|
32
|
+
url.product(345323423).variant(2421342331)
|
33
|
+
```
|
34
|
+
|
35
|
+
See the RDocs for a complete list of methods.
|
36
|
+
|
37
|
+
### Store URLs
|
38
|
+
```rb
|
39
|
+
require "shopify_url"
|
40
|
+
|
41
|
+
url = ShopifyURL::Store.new("shopname") # can also be the site's top-level domain
|
42
|
+
|
43
|
+
# https://shopname.myshopify.com/collections
|
44
|
+
url.collections
|
45
|
+
|
46
|
+
# https://shopname.myshopify.com/collections/amaaaaazing-thangz
|
47
|
+
url.collection("amaaaaazing-thangz")
|
48
|
+
```
|
49
|
+
|
50
|
+
See the RDocs for a complete list of methods.
|
51
|
+
|
52
|
+
### Query String Parameters
|
53
|
+
|
54
|
+
All Shopify URL generation methods accept a `Hash` of query string parameters:
|
55
|
+
|
56
|
+
```rb
|
57
|
+
url = ShopifyURL::Store.new("shopname") # can also be the site's top-level domain
|
58
|
+
|
59
|
+
# https://shopname.myshopify.com/products/some-handle?tracking=data
|
60
|
+
url.products("some-handle", :tracking => "data")
|
61
|
+
```
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
66
|
+
|
67
|
+
---
|
68
|
+
|
69
|
+
Made by [ScreenStaring](http://screenstaring.com)
|
data/Rakefile
ADDED
data/lib/shopify_url.rb
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module ShopifyURL
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
TOP_LEVEL_DOMAIN = ".myshopify.com"
|
7
|
+
|
8
|
+
class Linker
|
9
|
+
def initialize(shop)
|
10
|
+
raise ArgumentError, "shop required" if empty?(shop)
|
11
|
+
|
12
|
+
@host = shop.dup
|
13
|
+
@host.prepend("https://") unless @host =~ %r{\Ahttps?://}i
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@host.dup
|
18
|
+
end
|
19
|
+
|
20
|
+
alias to_str to_s
|
21
|
+
alias inspect to_s
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
attr_reader :host
|
26
|
+
|
27
|
+
def id_required!(id)
|
28
|
+
# Add caller to remove this frame from stack
|
29
|
+
raise ArgumentError, "id required", caller if id.to_s.strip.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def empty?(s)
|
33
|
+
s.to_s.strip.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
def q(params)
|
37
|
+
return unless params && params.respond_to?(:to_a)
|
38
|
+
URI.encode_www_form(params.to_a)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Store < Linker
|
43
|
+
class Collections < String
|
44
|
+
def initialize(host, id = nil, qs = nil)
|
45
|
+
super host + "/collections"
|
46
|
+
self << "/" << id if id
|
47
|
+
self << "?" << qs if qs
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Products < String
|
52
|
+
def initialize(host, qs = nil)
|
53
|
+
super host + "/products"
|
54
|
+
self << "?" << qs if qs
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Product < String
|
59
|
+
def initialize(host, id, qs = nil)
|
60
|
+
super host + "/products/" << id.to_s
|
61
|
+
self << "?" << qs if qs
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Blogs < String
|
66
|
+
def initialize(host, category, qs = nil)
|
67
|
+
super host + "/blogs"
|
68
|
+
self << "/" << category
|
69
|
+
self << "?" << qs if qs
|
70
|
+
end
|
71
|
+
|
72
|
+
def entry(name, params = nil)
|
73
|
+
self << "/" << name
|
74
|
+
self << "?" << URI.encode_www_form(params.to_a) if params && params.any?
|
75
|
+
self
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize(shop)
|
80
|
+
super
|
81
|
+
|
82
|
+
host << TOP_LEVEL_DOMAIN unless @host =~ %r{\.[-0-9a-z]+\z} # non-ASCII domains!
|
83
|
+
host.freeze
|
84
|
+
end
|
85
|
+
|
86
|
+
def collection(id, query = nil)
|
87
|
+
id_required!(id)
|
88
|
+
Collections.new(host, id, q(query))
|
89
|
+
end
|
90
|
+
|
91
|
+
def collections(query = nil)
|
92
|
+
Collections.new(host, nil, q(query))
|
93
|
+
end
|
94
|
+
|
95
|
+
def product(id, query = nil)
|
96
|
+
id_required!(id)
|
97
|
+
Product.new(host, id, q(query))
|
98
|
+
end
|
99
|
+
|
100
|
+
def products(query = nil)
|
101
|
+
Products.new(host, q(query))
|
102
|
+
end
|
103
|
+
|
104
|
+
def page(id, query = nil)
|
105
|
+
url = host + "/pages/" << id.to_s
|
106
|
+
url << "?" << q(query) if query
|
107
|
+
url
|
108
|
+
end
|
109
|
+
|
110
|
+
def blogs(category, query = nil)
|
111
|
+
raise "category required" if empty?(category)
|
112
|
+
Blogs.new(host, category, q(query))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class Admin < Linker
|
117
|
+
class Customers < String
|
118
|
+
def initialize(host, id = nil, qs = nil)
|
119
|
+
super host + "/customers"
|
120
|
+
self << "/" << id.to_s if id
|
121
|
+
self << "?" << qs if qs
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class Products < Store::Products
|
126
|
+
def inventory
|
127
|
+
self + "/inventory"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Product < Store::Product
|
132
|
+
def variants(id, params = nil)
|
133
|
+
url = self + "/variants/" << id.to_s
|
134
|
+
url << "?" << URI.encode_www_form(params.to_a) if params && params.any?
|
135
|
+
url
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class Order < String
|
140
|
+
def initialize(host, id, qs = nil)
|
141
|
+
super host + "/orders/" << id.to_s
|
142
|
+
self << "?" << qs if qs
|
143
|
+
end
|
144
|
+
|
145
|
+
def shipping_labels
|
146
|
+
ShippingLabel.new(self + "/shipping_labels")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class Orders < String
|
151
|
+
def initialize(host, qs = nil)
|
152
|
+
super host + "/orders"
|
153
|
+
self << "?" << qs if qs
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class ShippingLabel < String
|
158
|
+
def new(params = nil)
|
159
|
+
url = self + "/new"
|
160
|
+
url << "?" << URI.encode_www_form(params.to_a) if params && params.any?
|
161
|
+
url
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
class DraftOrder < String
|
166
|
+
def initialize(base, id, qs = nil)
|
167
|
+
super base + "/draft_orders/" << id.to_s
|
168
|
+
self << "?" << qs if qs
|
169
|
+
end
|
170
|
+
|
171
|
+
def duplicate(params = nil)
|
172
|
+
url = self + "/duplicate"
|
173
|
+
url << "?" << URI.encode_www_form(params.to_a) if params && params.any?
|
174
|
+
url
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class DraftOrders < String
|
179
|
+
def initialize(base, qs = nil)
|
180
|
+
super base + "/draft_orders"
|
181
|
+
self << "?" << qs if qs
|
182
|
+
end
|
183
|
+
|
184
|
+
def new(params = nil)
|
185
|
+
url = self + "/new"
|
186
|
+
url << "?" << URI.encode_www_form(params.to_a) if params && params.any?
|
187
|
+
url
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def initialize(shop)
|
192
|
+
super
|
193
|
+
host << TOP_LEVEL_DOMAIN unless host.end_with?(TOP_LEVEL_DOMAIN)
|
194
|
+
host << "/admin"
|
195
|
+
host.freeze
|
196
|
+
end
|
197
|
+
|
198
|
+
def customer(id, query = nil)
|
199
|
+
id_required!(id)
|
200
|
+
Customers.new(host, id, q(query))
|
201
|
+
end
|
202
|
+
|
203
|
+
def customers(query = nil)
|
204
|
+
Customers.new(host, nil, q(query))
|
205
|
+
end
|
206
|
+
|
207
|
+
def draft_orders(query = nil)
|
208
|
+
DraftOrders.new(host, q(query))
|
209
|
+
end
|
210
|
+
|
211
|
+
def draft_order(id, query = nil)
|
212
|
+
id_required!(id)
|
213
|
+
DraftOrder.new(host, id, q(query))
|
214
|
+
end
|
215
|
+
|
216
|
+
def order(id, query = nil)
|
217
|
+
id_required!(id)
|
218
|
+
Order.new(host, id, q(query))
|
219
|
+
end
|
220
|
+
|
221
|
+
def orders(query = nil)
|
222
|
+
Orders.new(host, q(query))
|
223
|
+
end
|
224
|
+
|
225
|
+
def product(id, query = nil)
|
226
|
+
id_required!(id)
|
227
|
+
Product.new(host, id, q(query))
|
228
|
+
end
|
229
|
+
|
230
|
+
def products(query = nil)
|
231
|
+
Products.new(host, q(query))
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
data/shopify_url.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "shopify_url"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shopify_url"
|
8
|
+
spec.version = ShopifyURL::VERSION
|
9
|
+
spec.authors = ["Skye Shaw"]
|
10
|
+
spec.email = ["skye.shaw@gmail.com"]
|
11
|
+
spec.summary = %q{Build URLs for Shopify websites}
|
12
|
+
spec.description = %q{Shopify URL allows you to build URLs to Shopify stores and the Admin site that can be used as links}
|
13
|
+
spec.homepage = "https://github.com/ScreenStaring/shopify_url"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify_url
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Skye Shaw
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Shopify URL allows you to build URLs to Shopify stores and the Admin
|
56
|
+
site that can be used as links
|
57
|
+
email:
|
58
|
+
- skye.shaw@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/shopify_url.rb
|
71
|
+
- shopify_url.gemspec
|
72
|
+
homepage: https://github.com/ScreenStaring/shopify_url
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Build URLs for Shopify websites
|
96
|
+
test_files: []
|