simple_gsx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5664ac0ee9454d0046198c8b37ea07ea3c1e460a
4
+ data.tar.gz: 1a46140ee7172f15e5d8c6534ff83a6fe6a3c568
5
+ SHA512:
6
+ metadata.gz: ea2889f932e8533cfc4afc2a0bbfd8175c9572989d7b4456c91c527a222248c5b26268f4387523aef71d2645b18abc3b7e10a2fa63f12b28a25cad0d058524d0
7
+ data.tar.gz: 5f4320f6a0fa70ed8c4cbe495969f070a81e96098263f774bd8d97e2b124260ea10318c39e849ffb37793328dc0358a4b91c8725d84dab047a2ae0d79f396342
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_gsx.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 zchar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,128 @@
1
+ # SimpleGsx
2
+
3
+ This gem is a Ruby library for communicating with Apple's GSX restful API.
4
+
5
+ You can visit [this site](https://gsxwsut.apple.com/apidocs/acc/uat/html/WSReference.html?user=reseller&id=1111&lang=EN) to see the full API documents.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'simple_gsx'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simple_gsx
20
+
21
+ ## Getting Started
22
+
23
+ In your project, initialize a GSX Client Object:
24
+
25
+ ```
26
+ require 'simple_gsx'
27
+
28
+ config = {
29
+ user_id: 'YOUR_USER_ID',
30
+ password: 'YOUR_PASSWORD',
31
+ ship_to: 'YOUR_SHIP_TO_CODE',
32
+ cert_file: '/PATH/TO/YOUR/CERT.pem',
33
+ lang_code: 'OPTIONAL, DEFAULT TO "zh"',
34
+ time_zone: 'OPTIONAL, DEFAULT TO "-480"'
35
+ }
36
+
37
+ gsx = SimpleGsx::Client.new(config)
38
+
39
+ # 360 lookup API request
40
+ lookup_params = {
41
+ device_id: 'YOUR_APPLE_DEVICE_ID',
42
+ purchase_order_number: 'OPTIONAL',
43
+ customer_email_id: 'OPTIONAL'
44
+ }
45
+ device_info = gsx.order_lookup(lookup_params)
46
+ ```
47
+
48
+ ## Other instance methods
49
+
50
+ ###create_order
51
+
52
+ ```
53
+ order_params = {
54
+ purchase_order_number: 'YOUR SYSTEM ORDER NUMBER, MAX TO 13 LENGTH',
55
+ customer_first_name: 'zheng',
56
+ customer_last_name: 'xu',
57
+ customer_email: 'zchar@mycolorway.com',
58
+ customer_address: 'CUSTOMER ADDRESS',
59
+ customer_mobile_number: 'CUSTOMER MOBILE NUMBER',
60
+ customer_zip_code: 'OPTIONAL, CUSTOMER ZIP CODE',
61
+ device_id: 'APPLE DEVICE ID',
62
+ created_at: Time.zone.now
63
+ }
64
+ gsx.create_order order_params
65
+ ```
66
+
67
+ ###cancel_order
68
+
69
+ ```
70
+ order_params = {
71
+ purchase_order_number: 'YOUR SYSTEM ORDER NUMBER, MAX TO 13 LENGTH',
72
+ customer_first_name: 'zheng',
73
+ customer_last_name: 'xu',
74
+ customer_email: 'zchar@mycolorway.com',
75
+ customer_address: 'CUSTOMER ADDRESS',
76
+ customer_mobile_number: 'CUSTOMER MOBILE NUMBER',
77
+ customer_zip_code: 'OPTIONAL, CUSTOMER ZIP CODE',
78
+ device_id: 'APPLE DEVICE ID',
79
+ created_at: Time.zone.now
80
+ }
81
+ gsx.cancel_order order_params
82
+ ```
83
+ ###verify_order
84
+ ```
85
+ order_params = {
86
+ purchase_order_number: 'YOUR SYSTEM ORDER NUMBER, MAX TO 13 LENGTH',
87
+ customer_first_name: 'zheng',
88
+ customer_last_name: 'xu',
89
+ customer_email: 'zchar@mycolorway.com',
90
+ customer_address: 'CUSTOMER ADDRESS',
91
+ customer_mobile_number: 'CUSTOMER MOBILE NUMBER',
92
+ customer_zip_code: 'OPTIONAL, CUSTOMER ZIP CODE',
93
+ device_id: 'APPLE DEVICE ID',
94
+ created_at: Time.zone.now
95
+ }
96
+ gsx.verify_order order_params
97
+ ```
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it ( http://github.com/<my-github-username>/simple_gsx/fork )
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
106
+
107
+ ## License
108
+
109
+ Copyright (c) 2008-2014 zchar@mycolorway.com
110
+
111
+ Permission is hereby granted, free of charge, to any person obtaining
112
+ a copy of this software and associated documentation files (the
113
+ "Software"), to deal in the Software without restriction, including
114
+ without limitation the rights to use, copy, modify, merge, publish,
115
+ distribute, sublicense, and/or sell copies of the Software, and to
116
+ permit persons to whom the Software is furnished to do so, subject to
117
+ the following conditions:
118
+
119
+ The above copyright notice and this permission notice shall be
120
+ included in all copies or substantial portions of the Software.
121
+
122
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
123
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
124
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
125
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
126
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
127
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
128
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,171 @@
1
+ require "simple_gsx/version"
2
+ require "rest-client"
3
+ require "json"
4
+
5
+ module SimpleGsx
6
+ class Client
7
+ attr_reader :cert_file, :user_id, :password, :ship_to,
8
+ :cert_file, :lang_code, :time_zone
9
+
10
+ API_BASE = 'https://api-acc-ept.apple.com'
11
+ API_VERSION = '1.0'
12
+
13
+ AUTH_URL = "#{API_BASE}/authentication-service/#{API_VERSION}/authenticate/"
14
+
15
+ CREATE_ORDER_URL = "#{API_BASE}/order-service/#{API_VERSION}/create-order/"
16
+ CANCEL_ORDER_URL = "#{API_BASE}/order-service/#{API_VERSION}/cancel-order/"
17
+ VERIFY_ORDER_URL = "#{API_BASE}/order-service/#{API_VERSION}/verify-order/"
18
+ LOOKUP_URL = "#{API_BASE}/order-service/#{API_VERSION}/get-order/"
19
+
20
+ def initialize options
21
+ @user_id = options.fetch :user_id
22
+ @password = options.fetch :password
23
+ @ship_to = options.fetch :ship_to
24
+ @cert_file = options.fetch :cert_file
25
+
26
+ # Options
27
+ @lang_code = options[:lang_code] || 'zh'
28
+ @time_zone = options[:time_zone] || '-480'
29
+ end
30
+
31
+ #
32
+ # See: https://gsxwsut.apple.com/apidocs/acc/uat/html/WSReference.html?user=reseller
33
+ # Section: Order/CreateOrder
34
+ #
35
+ def create_order options
36
+ body = {
37
+ requestContext: request_context,
38
+ appleCareSalesDate: options[:purchase_date].strftime('%y-%m-%d'),
39
+ pocLanguage: 'ZHS',
40
+ pocDeliveryPreference: 'E',
41
+ purchaseOrderNumber: options[:purchase_order_number],
42
+ MRC: '',
43
+ marketID: '',
44
+ overridePocFlag: '',
45
+ emailFlag: 'Y',
46
+ customerRequest: customer_request(options),
47
+ deviceRequest: [device_request(options)]
48
+ }
49
+
50
+ api_request CREATE_ORDER_URL, body
51
+ end
52
+
53
+ #
54
+ # See: https://gsxwsut.apple.com/apidocs/acc/uat/html/WSReference.html?user=reseller
55
+ # Section: Order/CancelOrder
56
+ #
57
+ def cancel_order options
58
+ body = {
59
+ deviceId: options[:device_id],
60
+ purchaseOrderNumber: options[:purchase_order_number],
61
+ cancellationDate: options[:cancel_date].strftime('%y-%m-%d'),
62
+ cancelReasonCode: options[:cancel_reason_code] || "",
63
+ requestContext: request_context
64
+ }
65
+
66
+ api_request CANCEL_ORDER_URL, body
67
+ end
68
+
69
+ #
70
+ # See: https://gsxwsut.apple.com/apidocs/acc/uat/html/WSReference.html?user=reseller
71
+ # Section: Order/VerifyOrder
72
+ #
73
+ def verify_order options
74
+ body = {
75
+ requestContext: request_context,
76
+ appleCareSalesDate: "",
77
+ pocLanguage: "ZHS",
78
+ pocDeliveryPreference: "",
79
+ purchaseOrderNumber: "",
80
+ MRC: "",
81
+ marketID: "",
82
+ overridePocFlag: "",
83
+ emailFlag: "Y",
84
+ customerRequest: customer_request(options),
85
+ deviceRequest: [device_request(options)]
86
+ }
87
+
88
+ api_request VERIFY_ORDER_URL, body
89
+ end
90
+
91
+ #
92
+ # See: https://gsxwsut.apple.com/apidocs/acc/uat/html/WSReference.html?user=reseller
93
+ # Section: 360 Look Up
94
+ #
95
+ def order_lookup options
96
+ body = {
97
+ requestContext: request_context,
98
+ deviceId: options[:device_id],
99
+ purchaseOrderNumber: options[:purchase_order_number] || "",
100
+ customerEmailId: options[:customer_email_id] || ""
101
+ }
102
+
103
+ api_request LOOKUP_URL, body
104
+ end
105
+
106
+ private
107
+
108
+ def json json_string
109
+ JSON.parse json_string, symbolize_names: true
110
+ end
111
+
112
+ def headers
113
+ { accAccessToken: access_token, :'content-type' => 'application/json' }
114
+ end
115
+
116
+ def request_context
117
+ { shipTo: ship_to, timeZone: time_zone, langCode: lang_code }
118
+ end
119
+
120
+ def customer_request options
121
+ {
122
+ customerFirstName: options[:customer_first_name] || "",
123
+ customerLastName: options[:customer_last_name] || "",
124
+ companyName: "",
125
+ customerEmailId: options[:customer_email],
126
+ addressLine1: options[:customer_address],
127
+ addressLine2: "",
128
+ city: "",
129
+ stateCode: "230",
130
+ countryCode: "CN",
131
+ primaryPhoneNumber: options[:customer_mobile_number],
132
+ zipCode: options[:customer_zip_code]
133
+ }
134
+ end
135
+
136
+ def device_request options
137
+ {
138
+ deviceId: options[:device_id],
139
+ secondarySerialNumber: options[:secondary_device_id] || "",
140
+ hardwareDateOfPurchase: options[:date_of_purchase] || "" #"09/11/13"
141
+ }
142
+ end
143
+
144
+ def access_token
145
+ @access_token ||= begin
146
+ body = {
147
+ userId: user_id,
148
+ password: password,
149
+ shipTo: ship_to,
150
+ langCode: lang_code,
151
+ timeZone: time_zone
152
+ }
153
+
154
+ response = api_request AUTH_URL, body
155
+ response[:accessToken]
156
+ end
157
+ end
158
+
159
+ def api_request url, body
160
+ response = RestClient::Resource.new(
161
+ url,
162
+ :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read(cert_file)),
163
+ :ssl_client_key => OpenSSL::PKey::RSA.new(File.read(cert_file), ''),
164
+ :ssl_ca_file => cert_file,
165
+ :verify_ssl => false
166
+ ).post JSON.dump(body), headers
167
+
168
+ json response
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleGsx
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_gsx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_gsx"
8
+ spec.version = SimpleGsx::VERSION
9
+ spec.authors = ["zchar"]
10
+ spec.email = ["zchar@mycolorway.com"]
11
+ spec.summary = %q{Apple GSX API Library}
12
+ spec.description = %q{A Ruby library for communicating with Apple's GSX restful API}
13
+ spec.homepage = "https://github.com/mycolorway/simple_gsx"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+
25
+ spec.add_dependency 'rest-client', '~> 1.6'
26
+ spec.add_dependency 'json', '~> 1.8'
27
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_gsx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - zchar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-22 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: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: A Ruby library for communicating with Apple's GSX restful API
70
+ email:
71
+ - zchar@mycolorway.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/simple_gsx.rb
82
+ - lib/simple_gsx/version.rb
83
+ - simple_gsx.gemspec
84
+ homepage: https://github.com/mycolorway/simple_gsx
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.9.3
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Apple GSX API Library
108
+ test_files: []