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,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class PaymentMethod < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "payment_methods#{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 = "payment_methods/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 = "payment_methods/#{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 Product < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "products#{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 = "products/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 = "products/#{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 = "products"
|
|
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 = "products/#{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 = "products/#{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 ProductImage < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, product_id, params = nil)
|
|
6
|
+
path = "products/#{product_id}/images#{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, product_id)
|
|
12
|
+
path = "products/#{product_id}/images/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, product_id, id, params = nil)
|
|
18
|
+
path = "products/#{product_id}/images/#{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, product_id, params)
|
|
24
|
+
path = "products/#{product_id}/images"
|
|
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, product_id, id, params)
|
|
30
|
+
path = "products/#{product_id}/images/#{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, product_id, id)
|
|
36
|
+
path = "products/#{product_id}/images/#{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 ProductVariant < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, product_id, params = nil)
|
|
6
|
+
path = "products/#{product_id}/variants#{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, product_id)
|
|
12
|
+
path = "products/#{product_id}/variants/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, product_id, id, params = nil)
|
|
18
|
+
path = "products/#{product_id}/variants/#{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, product_id, params)
|
|
24
|
+
path = "products/#{product_id}/variants"
|
|
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, product_id, id, params)
|
|
30
|
+
path = "products/#{product_id}/variants/#{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, product_id, id)
|
|
36
|
+
path = "products/#{product_id}/variants/#{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 Province < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, country_id, params = nil)
|
|
6
|
+
path = "countries/#{country_id}/provinces#{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)
|
|
12
|
+
path = "countries/#{country_id}/provinces/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, id, params = nil)
|
|
18
|
+
path = "countries/#{country_id}/provinces/#{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 Redirect < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "redirects#{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 = "redirects/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 = "redirects/#{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 = "redirects"
|
|
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 = "redirects/#{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 = "redirects/#{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 ScriptTag < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "script_tags#{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 = "script_tags/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 = "script_tags/#{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 = "script_tags"
|
|
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 = "script_tags/#{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 = "script_tags/#{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,37 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Shipment < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "shipments#{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 = "shipments/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 = "shipments/#{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 = "shipments/#{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
|
+
def self.send(token, id)
|
|
30
|
+
path = "shipments/#{id}/send"
|
|
31
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
32
|
+
YhsdApi::HTTP::put(uri, {}.to_json, build_header(token))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class ShipmentSupplier < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "shipment_suppliers#{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 = "shipment_suppliers/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 = "shipment_suppliers/#{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,13 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Shop < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.info(token, params = {})
|
|
6
|
+
path = "shop#{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
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module YhsdApi
|
|
2
|
+
|
|
3
|
+
class Theme < YhsdApi::Base
|
|
4
|
+
|
|
5
|
+
def self.all(token, params = nil)
|
|
6
|
+
path = "themes#{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 = "themes/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 = "themes/#{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 = "themes/#{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
|
+
def self.delete(token, id)
|
|
30
|
+
path = "themes/#{id}"
|
|
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,45 @@
|
|
|
1
|
+
require 'openssl'
|
|
2
|
+
|
|
3
|
+
module YhsdApi
|
|
4
|
+
|
|
5
|
+
class Webhook < YhsdApi::Base
|
|
6
|
+
|
|
7
|
+
def self.all(token, params = nil)
|
|
8
|
+
path = "webhooks#{handle_query_string(params)}"
|
|
9
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
10
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.count(token)
|
|
14
|
+
path = "webhooks/count"
|
|
15
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
16
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.find(token, id, params = nil)
|
|
20
|
+
path = "webhooks/#{id}#{handle_query_string(params)}"
|
|
21
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
22
|
+
YhsdApi::HTTP::get(uri, build_header(token))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.create(token, params)
|
|
26
|
+
path = "webhooks"
|
|
27
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
28
|
+
YhsdApi::HTTP::post(uri, params.to_json, build_header(token))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.update(token, id, params)
|
|
32
|
+
path = "webhooks/#{id}"
|
|
33
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
34
|
+
YhsdApi::HTTP::put(uri, params.to_json, build_header(token))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.delete(token, id)
|
|
38
|
+
path = "webhooks/#{id}"
|
|
39
|
+
uri = URI.join(YhsdApi.configuration.api_url, YhsdApi.configuration.api_version, path)
|
|
40
|
+
YhsdApi::HTTP::delete(uri, build_header(token))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
data/lib/yhsd_api.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'oj'
|
|
3
|
+
require 'openssl'
|
|
4
|
+
require "yhsd_api/version"
|
|
5
|
+
require "yhsd_api/helper"
|
|
6
|
+
require "yhsd_api/configuration"
|
|
7
|
+
require "yhsd_api/http"
|
|
8
|
+
require "yhsd_api/exception"
|
|
9
|
+
require "yhsd_api/public_app"
|
|
10
|
+
require "yhsd_api/private_app"
|
|
11
|
+
require "yhsd_api/resources"
|
|
12
|
+
|
|
13
|
+
module YhsdApi
|
|
14
|
+
# Your code goes here...
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe YhsdApi::Configuration do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
YhsdApi.configure do |config|
|
|
7
|
+
config.app_key = 'd677ae82993a48fcaaf3c05ead9f46ea'
|
|
8
|
+
config.app_secret = '6e6d1e96f23f49a1a59f9ce87fed1763'
|
|
9
|
+
config.scope = 'read_basic,
|
|
10
|
+
write_basic'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "configure app_key" do
|
|
15
|
+
expect(YhsdApi.configuration.app_key).to eq('d677ae82993a48fcaaf3c05ead9f46ea')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "configure app_secret" do
|
|
19
|
+
expect(YhsdApi.configuration.app_secret).to eq('6e6d1e96f23f49a1a59f9ce87fed1763')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "configure scope" do
|
|
23
|
+
expect(YhsdApi.configuration.scope).to eq('read_basic,write_basic')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "configure default token_url" do
|
|
27
|
+
expect(YhsdApi.configuration.token_url).to eq('https://apps.youhaosuda.com/oauth2/token/')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "configure default api_url" do
|
|
31
|
+
expect(YhsdApi.configuration.api_url).to eq('https://api.youhaosuda.com/')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "configure default auth_url" do
|
|
35
|
+
expect(YhsdApi.configuration.auth_url).to eq('https://apps.youhaosuda.com/oauth2/authorize/')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "configure default api_version" do
|
|
39
|
+
expect(YhsdApi.configuration.api_version).to eq("v1/")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "api version " do
|
|
43
|
+
YhsdApi.configure do |config|
|
|
44
|
+
config.api_version = "v1"
|
|
45
|
+
end
|
|
46
|
+
expect(YhsdApi.configuration.api_version).to eq("v1/")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
data/spec/helper_spec.rb
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe YhsdApi::Helper do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "authorization must be success" do
|
|
10
|
+
key = 'a94a110d86d2452eb3e2af4cfb8a3828'
|
|
11
|
+
secret = 'a84a110d86d2452eb3e2af4cfb8a3828'
|
|
12
|
+
result = "Basic YTk0YTExMGQ4NmQyNDUyZWIzZTJhZjRjZmI4YTM4Mjg6YTg0YTExMGQ4NmQyNDUyZWIzZTJhZjRjZmI4YTM4Mjg="
|
|
13
|
+
expect(YhsdApi::Helper::authorization(key, secret)).to eq(result)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "symbol hmac_verify must be success" do
|
|
17
|
+
params = {
|
|
18
|
+
"shop_key": "a94a110d86d2452eb3e2af4cfb8a3828",
|
|
19
|
+
"code": "a84a110d86d2452eb3e2af4cfb8a3828",
|
|
20
|
+
"account_id": "1",
|
|
21
|
+
"time_stamp": "2013-08-27T13:58:35Z",
|
|
22
|
+
"hmac": "a2a3e2dcd8a82fd9070707d4d921ac4cdc842935bf57bc38c488300ef3960726"
|
|
23
|
+
}
|
|
24
|
+
secret = "hush"
|
|
25
|
+
expect(YhsdApi::Helper::hmac_verify(secret, params)).to eq(true)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "string hmac_verify must be success" do
|
|
29
|
+
params = {
|
|
30
|
+
"shop_key" => "a94a110d86d2452eb3e2af4cfb8a3828",
|
|
31
|
+
"code" => "a84a110d86d2452eb3e2af4cfb8a3828",
|
|
32
|
+
"account_id" => "1",
|
|
33
|
+
"time_stamp" => "2013-08-27T13:58:35Z",
|
|
34
|
+
"hmac" => "a2a3e2dcd8a82fd9070707d4d921ac4cdc842935bf57bc38c488300ef3960726"
|
|
35
|
+
}
|
|
36
|
+
secret = "hush"
|
|
37
|
+
expect(YhsdApi::Helper::hmac_verify(secret, params)).to eq(true)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "string generate_hmac must be success" do
|
|
41
|
+
params = {
|
|
42
|
+
"shop_key" => "a94a110d86d2452eb3e2af4cfb8a3828",
|
|
43
|
+
"code" => "a84a110d86d2452eb3e2af4cfb8a3828",
|
|
44
|
+
"account_id" => "1",
|
|
45
|
+
"time_stamp" => "2013-08-27T13:58:35Z"
|
|
46
|
+
}
|
|
47
|
+
secret = "hush"
|
|
48
|
+
expect(YhsdApi::Helper::generate_hmac(secret, params)).to eq('a2a3e2dcd8a82fd9070707d4d921ac4cdc842935bf57bc38c488300ef3960726')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "webhook_verify must be success" do
|
|
52
|
+
data ="{\"created_at\":\"2014-08-28T17:28:13.301+08:00\",\"domain\":\"www.example.com\",\"enable_email_regist\":true,\"enable_mobile_regist\":true,\"enable_username_regist\":true,\"name\":\"TEST\",\"page_description\":\"\",\"page_title\":\"\",\"updated_at\":\"2015-07-27T13:58:14.607+08:00\",\"url\":\"http://w...content-available-to-author-only...e.com\",\"webhook_token\":\"906155047ff74a14a1ca6b1fa74d3390\"}"
|
|
53
|
+
webhook_token = "906155047ff74a14a1ca6b1fa74d3390"
|
|
54
|
+
hmac = "0pGPxJlI/GFfnUm9SX2mauyQ7q57JqyJNXDid+0iouY="
|
|
55
|
+
expect(YhsdApi::Helper::webhook_verify(webhook_token, data, hmac)).to eq(true)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "openpayment_verify must be success" do
|
|
59
|
+
data ="{\"created_at\":\"2014-08-28T17:28:13.301+08:00\",\"domain\":\"www.example.com\",\"enable_email_regist\":true,\"enable_mobile_regist\":true,\"enable_username_regist\":true,\"name\":\"TEST\",\"page_description\":\"\",\"page_title\":\"\",\"updated_at\":\"2015-07-27T13:58:14.607+08:00\",\"url\":\"http://w...content-available-to-author-only...e.com\",\"webhook_token\":\"906155047ff74a14a1ca6b1fa74d3390\"}"
|
|
60
|
+
webhook_token = "906155047ff74a14a1ca6b1fa74d3390"
|
|
61
|
+
hmac = "0pGPxJlI/GFfnUm9SX2mauyQ7q57JqyJNXDid+0iouY="
|
|
62
|
+
expect(YhsdApi::Helper::openpayment_verify(webhook_token, data, hmac)).to eq(true)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "thirdapp_aes_encrypt must be success" do
|
|
66
|
+
customer_data = {
|
|
67
|
+
"uid" => "test@youhaosuda.com",
|
|
68
|
+
"type" => "email",
|
|
69
|
+
"name" => "test"
|
|
70
|
+
}
|
|
71
|
+
secret = '3B975F95D7734B4094239E8CB46C4B7C'
|
|
72
|
+
expect(YhsdApi::Helper::thirdapp_aes_encrypt(secret, customer_data.to_json)).to be_kind_of(String)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe YhsdApi::PrivateApp do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
YhsdApi.configure do |config|
|
|
7
|
+
config.app_key = '0249cb63872d43a28c0d9bf0ddfd6a9c'
|
|
8
|
+
config.app_secret = '45ab37bed9334b86b4cb6be2b4459cdf'
|
|
9
|
+
config.call_limit_protect = true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "token is nil should raises error" do
|
|
14
|
+
path = "products"
|
|
15
|
+
expect {code, body, header = YhsdApi::PrivateApp.get(YhsdApi.configuration.api_url + path)}.to raise_error(YhsdApi::MissingToken)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "url is null should raises error" do
|
|
19
|
+
YhsdApi::PrivateApp.generate_token
|
|
20
|
+
expect {code, body, header = YhsdApi::PrivateApp.get(nil)}.to raise_error(YhsdApi::MissingURI)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "private app generate_token" do
|
|
24
|
+
token = YhsdApi::PrivateApp.generate_token
|
|
25
|
+
expect(token).to be_kind_of(String)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "private app get" do
|
|
29
|
+
YhsdApi::PrivateApp.generate_token
|
|
30
|
+
path = "redirects"
|
|
31
|
+
code, body, header = YhsdApi::PrivateApp.get(path)
|
|
32
|
+
expect(code).to eq(200)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "private app post" do
|
|
36
|
+
YhsdApi::PrivateApp.generate_token
|
|
37
|
+
path = "redirects"
|
|
38
|
+
params = {
|
|
39
|
+
"redirect": {
|
|
40
|
+
"path": "/123",
|
|
41
|
+
"target": "/blogs"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
code, body, header = YhsdApi::PrivateApp.post(path, params)
|
|
45
|
+
expect([200, 422]).to include(code)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "private app put" do
|
|
49
|
+
YhsdApi::PrivateApp.generate_token
|
|
50
|
+
path = "redirects/23"
|
|
51
|
+
params = {
|
|
52
|
+
"redirect": {
|
|
53
|
+
"path": "/66",
|
|
54
|
+
"target": "/blogs"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
code, body, header = YhsdApi::PrivateApp.put(path, params)
|
|
58
|
+
expect([200, 422]).to include(code)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "private app delete" do
|
|
62
|
+
YhsdApi::PrivateApp.generate_token
|
|
63
|
+
path = "redirects/23"
|
|
64
|
+
code, body, header = YhsdApi::PrivateApp.delete(path)
|
|
65
|
+
expect([200, 422]).to include(code)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|