yhsd_api 0.0.3
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 +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +5 -0
- data/ChangeLog.md +54 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +242 -0
- data/Rakefile +2 -0
- data/lib/yhsd_api/configuration.rb +48 -0
- data/lib/yhsd_api/exception.rb +41 -0
- data/lib/yhsd_api/helper.rb +78 -0
- data/lib/yhsd_api/http.rb +135 -0
- data/lib/yhsd_api/private_app.rb +114 -0
- data/lib/yhsd_api/public_app.rb +124 -0
- data/lib/yhsd_api/resources/account.rb +25 -0
- data/lib/yhsd_api/resources/asset.rb +37 -0
- data/lib/yhsd_api/resources/base.rb +25 -0
- data/lib/yhsd_api/resources/city.rb +25 -0
- data/lib/yhsd_api/resources/country.rb +25 -0
- data/lib/yhsd_api/resources/customer.rb +43 -0
- data/lib/yhsd_api/resources/customer_address.rb +43 -0
- data/lib/yhsd_api/resources/district.rb +25 -0
- data/lib/yhsd_api/resources/metafield.rb +55 -0
- data/lib/yhsd_api/resources/open_payment.rb +31 -0
- data/lib/yhsd_api/resources/order.rb +31 -0
- data/lib/yhsd_api/resources/page.rb +43 -0
- data/lib/yhsd_api/resources/payment.rb +25 -0
- data/lib/yhsd_api/resources/payment_method.rb +25 -0
- data/lib/yhsd_api/resources/product.rb +43 -0
- data/lib/yhsd_api/resources/product_image.rb +43 -0
- data/lib/yhsd_api/resources/product_variant.rb +43 -0
- data/lib/yhsd_api/resources/province.rb +25 -0
- data/lib/yhsd_api/resources/redirect.rb +43 -0
- data/lib/yhsd_api/resources/script_tag.rb +43 -0
- data/lib/yhsd_api/resources/shipment.rb +37 -0
- data/lib/yhsd_api/resources/shipment_supplier.rb +25 -0
- data/lib/yhsd_api/resources/shop.rb +13 -0
- data/lib/yhsd_api/resources/theme.rb +37 -0
- data/lib/yhsd_api/resources/webhook.rb +45 -0
- data/lib/yhsd_api/resources.rb +2 -0
- data/lib/yhsd_api/version.rb +3 -0
- data/lib/yhsd_api.rb +16 -0
- data/spec/configuration_spec.rb +49 -0
- data/spec/helper_spec.rb +75 -0
- data/spec/private_app_spec.rb +68 -0
- data/spec/public_app_spec.rb +93 -0
- data/spec/resources/account_spec.rb +31 -0
- data/spec/resources/asset_spec.rb +56 -0
- data/spec/resources/city_spec.rb +30 -0
- data/spec/resources/country_spec.rb +28 -0
- data/spec/resources/customer_address_spec.rb +66 -0
- data/spec/resources/customer_spec.rb +67 -0
- data/spec/resources/district_spec.rb +31 -0
- data/spec/resources/metafield_spec.rb +79 -0
- data/spec/resources/open_payment_spec.rb +40 -0
- data/spec/resources/order_spec.rb +41 -0
- data/spec/resources/page_spec.rb +54 -0
- data/spec/resources/payment_method_spec.rb +28 -0
- data/spec/resources/payment_spec.rb +29 -0
- data/spec/resources/product_image_spec.rb +59 -0
- data/spec/resources/product_spec.rb +123 -0
- data/spec/resources/product_variant_spec.rb +74 -0
- data/spec/resources/province_spec.rb +29 -0
- data/spec/resources/redirect_spec.rb +58 -0
- data/spec/resources/script_tag_spec.rb +54 -0
- data/spec/resources/shipment_spec.rb +43 -0
- data/spec/resources/shipment_supplier_spec.rb +31 -0
- data/spec/resources/shop_spec.rb +18 -0
- data/spec/resources/theme_spec.rb +38 -0
- data/spec/resources/webhook_spec.rb +54 -0
- data/spec/spec_helper.rb +9 -0
- data/yhsd_api.gemspec +26 -0
- metadata +217 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class PrivateApp
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
attr_accessor :token
|
|
8
|
+
|
|
9
|
+
###
|
|
10
|
+
#友好速搭私有App 获取API调用token 方法
|
|
11
|
+
###
|
|
12
|
+
def generate_token
|
|
13
|
+
|
|
14
|
+
req_body = {
|
|
15
|
+
"grant_type" => 'client_credentials'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
opts = {
|
|
19
|
+
:headers =>{
|
|
20
|
+
:Authorization => YhsdApi::Helper::authorization(YhsdApi.configuration.app_key,YhsdApi.configuration.app_secret),
|
|
21
|
+
:content_type => "application/x-www-form-urlencoded"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
code, body, header = HTTP::post(YhsdApi.configuration.token_url, req_body, opts)
|
|
26
|
+
if code == 200
|
|
27
|
+
@token = Oj.load(body)["token"]
|
|
28
|
+
@token
|
|
29
|
+
else
|
|
30
|
+
raise Exception.new(body)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def get(url)
|
|
36
|
+
|
|
37
|
+
validate_token
|
|
38
|
+
|
|
39
|
+
opts = {:headers => {
|
|
40
|
+
"X-API-ACCESS-TOKEN" => @token
|
|
41
|
+
}}
|
|
42
|
+
|
|
43
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
44
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
YhsdApi::HTTP::get(url, opts)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def delete(url)
|
|
51
|
+
|
|
52
|
+
validate_token
|
|
53
|
+
|
|
54
|
+
opts = {:headers => {
|
|
55
|
+
"X-API-ACCESS-TOKEN" => @token
|
|
56
|
+
}}
|
|
57
|
+
|
|
58
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
59
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
YhsdApi::HTTP::delete(url, opts)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def post(url, req_body)
|
|
66
|
+
|
|
67
|
+
validate_token
|
|
68
|
+
|
|
69
|
+
opts = {:headers => {
|
|
70
|
+
"X-API-ACCESS-TOKEN" => @token,
|
|
71
|
+
:content_type => :json,
|
|
72
|
+
:accept => :json
|
|
73
|
+
}}
|
|
74
|
+
|
|
75
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
76
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
YhsdApi::HTTP::post(url, req_body.to_json, opts)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def put(url, req_body)
|
|
83
|
+
|
|
84
|
+
validate_token
|
|
85
|
+
|
|
86
|
+
opts = {:headers => {
|
|
87
|
+
"X-API-ACCESS-TOKEN" => @token,
|
|
88
|
+
:content_type => :json,
|
|
89
|
+
:accept => :json
|
|
90
|
+
}}
|
|
91
|
+
|
|
92
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
93
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
YhsdApi::HTTP::put(url, req_body.to_json, opts)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def validate_token
|
|
100
|
+
raise MissingToken if @token.to_s.empty?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def handle_query_string(params)
|
|
104
|
+
return '' unless params === Hash
|
|
105
|
+
params.keys.map do |k|
|
|
106
|
+
"#{CGI.escape(k.to_s)}=#{CGI.escape(params[k].to_s)}"
|
|
107
|
+
end.join('&')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class PublicApp
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
###
|
|
8
|
+
#生成友好速搭安装回调地址方法
|
|
9
|
+
###
|
|
10
|
+
def authorize_url(redirect_uri, shop_key, state = '')
|
|
11
|
+
raise MissingAppKey if YhsdApi.configuration.app_key.to_s.empty?
|
|
12
|
+
raise MissingScope if YhsdApi.configuration.scope.to_s.empty?
|
|
13
|
+
|
|
14
|
+
params = "?response_type=code"
|
|
15
|
+
params +="&client_id=#{YhsdApi.configuration.app_key}"
|
|
16
|
+
params +="&shop_key=#{shop_key}"
|
|
17
|
+
params +="&scope=#{YhsdApi.configuration.scope}"
|
|
18
|
+
params +="&redirect_uri=#{redirect_uri}"
|
|
19
|
+
params +="&state=#{state}" unless state.to_s.empty?
|
|
20
|
+
|
|
21
|
+
URI.join(YhsdApi.configuration.auth_url, params).to_s
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
#通过友好速搭分发的code获取店铺访问token方法
|
|
26
|
+
###
|
|
27
|
+
def generate_token(redirect_uri, code)
|
|
28
|
+
raise MissingAppKey if YhsdApi.configuration.app_key.to_s.empty?
|
|
29
|
+
|
|
30
|
+
req_body = {
|
|
31
|
+
"grant_type" => 'authorization_code',
|
|
32
|
+
"code" => code,
|
|
33
|
+
"client_id" => YhsdApi.configuration.app_key,
|
|
34
|
+
"redirect_uri" => redirect_uri
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
opts = {
|
|
38
|
+
:headers =>{
|
|
39
|
+
:content_type => "application/x-www-form-urlencoded"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
code, body, header = HTTP::post(YhsdApi.configuration.token_url, req_body, opts)
|
|
44
|
+
if code == 200
|
|
45
|
+
Oj.load(body)["token"]
|
|
46
|
+
else
|
|
47
|
+
raise Exception.new(body)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get(token, url)
|
|
53
|
+
validate_token(token)
|
|
54
|
+
|
|
55
|
+
opts = {:headers => {
|
|
56
|
+
"X-API-ACCESS-TOKEN" => token
|
|
57
|
+
}}
|
|
58
|
+
|
|
59
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
60
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
YhsdApi::HTTP::get(url, opts)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def delete(token, url)
|
|
67
|
+
validate_token(token)
|
|
68
|
+
|
|
69
|
+
opts = {:headers => {
|
|
70
|
+
"X-API-ACCESS-TOKEN" => token
|
|
71
|
+
}}
|
|
72
|
+
|
|
73
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
74
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
YhsdApi::HTTP::delete(url, opts)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def post(token, url, req_body)
|
|
81
|
+
validate_token(token)
|
|
82
|
+
|
|
83
|
+
opts = {:headers => {
|
|
84
|
+
"X-API-ACCESS-TOKEN" => token,
|
|
85
|
+
:content_type => :json,
|
|
86
|
+
:accept => :json
|
|
87
|
+
}}
|
|
88
|
+
|
|
89
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
90
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
YhsdApi::HTTP::post(url, req_body.to_json, opts)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def put(token, url, req_body)
|
|
97
|
+
validate_token(token)
|
|
98
|
+
|
|
99
|
+
opts = {:headers => {
|
|
100
|
+
"X-API-ACCESS-TOKEN" => token,
|
|
101
|
+
:content_type => :json,
|
|
102
|
+
:accept => :json
|
|
103
|
+
}}
|
|
104
|
+
|
|
105
|
+
if url && !url.start_with?('http://') && !url.start_with?('https://')
|
|
106
|
+
url = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, url)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
YhsdApi::HTTP::put(url, req_body.to_json, opts)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def validate_token token
|
|
113
|
+
raise MissingToken if token.to_s.empty?
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def verify_hmac(params)
|
|
117
|
+
YhsdApi::Helper::hmac_verify(YhsdApi.configuration.app_secret, params)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Account < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "accounts#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token)
|
|
12
|
+
path = "accounts/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "accounts/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Asset < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, theme_id, params = nil)
|
|
6
|
+
path = "themes/#{theme_id}/assets#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.find(token, theme_id, params = nil)
|
|
12
|
+
path = "themes/#{theme_id}/assets#{handle_query_string(params)}"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.create(token, theme_id, params = {})
|
|
18
|
+
path = "themes/#{theme_id}/assets"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.update(token, theme_id, params)
|
|
24
|
+
path = "themes/#{theme_id}/assets"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.delete(token, theme_id, params = nil)
|
|
30
|
+
path = "themes/#{theme_id}/assets#{handle_query_string(params)}"
|
|
31
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
32
|
+
YhsdApi::HTTP::delete(uri, build_header(token))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Base
|
|
4
|
+
|
|
5
|
+
def self.handle_query_string(params = {})
|
|
6
|
+
if params.is_a?(Hash) && !params.empty?
|
|
7
|
+
return "?" + params.keys.map do |key|
|
|
8
|
+
"#{key.to_s}=#{params[key].to_s}"
|
|
9
|
+
end.join("&")
|
|
10
|
+
else
|
|
11
|
+
return ''
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.build_header(token)
|
|
16
|
+
{:headers => {
|
|
17
|
+
"X-API-ACCESS-TOKEN" => token,
|
|
18
|
+
:content_type => :json,
|
|
19
|
+
:accpet => :json
|
|
20
|
+
}}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class City < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, country_id, province_id, params = nil)
|
|
6
|
+
path = "countries/#{country_id}/provinces/#{province_id}/cities#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token, country_id, province_id)
|
|
12
|
+
path = "countries/#{country_id}/provinces/#{province_id}/cities/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, country_id, province_id, id, params = nil)
|
|
18
|
+
path = "countries/#{country_id}/provinces/#{province_id}/cities/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Country < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "countries#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token)
|
|
12
|
+
path = "countries/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "countries/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Customer < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "customers#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token)
|
|
12
|
+
path = "customers/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "customers/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.create(token, params)
|
|
24
|
+
path = "customers"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.update(token, id, params)
|
|
30
|
+
path = "customers/#{id}"
|
|
31
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
32
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.delete(token, id)
|
|
36
|
+
path = "customers/#{id}"
|
|
37
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
38
|
+
YhsdApi::HTTP::delete(uri, build_header(token))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class CustomerAddress < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, customer_id, params = nil)
|
|
6
|
+
path = "customers/#{customer_id}/addresses#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token, customer_id)
|
|
12
|
+
path = "customers/#{customer_id}/addresses/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, customer_id, id, params = nil)
|
|
18
|
+
path = "customers/#{customer_id}/addresses/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.create(token, customer_id, params)
|
|
24
|
+
path = "customers/#{customer_id}/addresses"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.update(token, customer_id, id, params)
|
|
30
|
+
path = "customers/#{customer_id}/addresses/#{id}"
|
|
31
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
32
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.delete(token, customer_id, id)
|
|
36
|
+
path = "customers/#{customer_id}/addresses/#{id}"
|
|
37
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
38
|
+
YhsdApi::HTTP::delete(uri, build_header(token))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class District < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, country_id, province_id, city_id, params = nil)
|
|
6
|
+
path = "countries/#{country_id}/provinces/#{province_id}/cities/#{city_id}/districts#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token, country_id, province_id, city_id)
|
|
12
|
+
path = "countries/#{country_id}/provinces/#{province_id}/cities/#{city_id}/districts/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, country_id, province_id, city_id, id, params = nil)
|
|
18
|
+
path = "countries/#{country_id}/provinces/#{province_id}/cities/#{city_id}/districts/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Metafield < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.count(token)
|
|
6
|
+
path = "metas/count"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.all(token, params = nil)
|
|
12
|
+
path = "metas#{handle_query_string(params)}"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "metas/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, uri)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.create(token, params)
|
|
24
|
+
path = "metas"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.update(token, id, params)
|
|
30
|
+
path = "metas/#{id}"
|
|
31
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
32
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.delete(token, id)
|
|
36
|
+
path = "metas/#{id}"
|
|
37
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
38
|
+
YhsdApi::HTTP::delete(uri, build_header(token))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.update_fields(token, id, params)
|
|
42
|
+
path = "metas/#{id}/fields"
|
|
43
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
44
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.find_fields(token, id, params = nil)
|
|
48
|
+
path = "metas/#{id}/fields#{handle_query_string(params)}"
|
|
49
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
50
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class OpenPayment < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "open_payments#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token)
|
|
12
|
+
path = "open_payments/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "open_payments/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.create(token, params = nil)
|
|
24
|
+
path = "open_payments"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Order < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "orders#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token)
|
|
12
|
+
path = "orders/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "orders/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.update(token, id, params)
|
|
24
|
+
path = "orders/#{id}"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Page < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "pages#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token)
|
|
12
|
+
path = "pages/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, id, params = nil)
|
|
18
|
+
path = "pages/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.create(token, params)
|
|
24
|
+
path = "pages"
|
|
25
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
26
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.update(token, id, params)
|
|
30
|
+
path = "pages/#{id}"
|
|
31
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
32
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.delete(token, id)
|
|
36
|
+
path = "pages/#{id}"
|
|
37
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
38
|
+
YhsdApi::HTTP::delete(uri, build_header(token))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Payment < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, order_id, params = nil)
|
|
6
|
+
path = "orders/#{order_id}/payments#{handle_query_string(params)}"
|
|
7
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
8
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.count(token, order_id)
|
|
12
|
+
path = "orders/#{order_id}/payments/count"
|
|
13
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
14
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find(token, order_id, id, params = nil)
|
|
18
|
+
path = "orders/#{order_id}/payments/#{id}#{handle_query_string(params)}"
|
|
19
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
20
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|