acc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/acc.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/acc/bulk_enroll_response.rb +35 -0
- data/lib/acc/check_transaction_response.rb +65 -0
- data/lib/acc/service.rb +35 -0
- data/lib/acc/version.rb +3 -0
- data/lib/acc.rb +12 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 792b010349a662bde2b89ed41e4f7a6ecc4a7f6b
|
4
|
+
data.tar.gz: 765f8f6a65159ecd919a2650cbd04db45c9f91f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83a804090456fc6a2048056f7003189aa3730327c0e21e777cfe82a8d62415f2693ad9462fb2adb5720e0015605cb41f36cf76e7715c2c1d95e5e0afbe6bcd0a
|
7
|
+
data.tar.gz: 5394aabfabeadd2932d91b92c4faf18bdaa6c59d4abb7a8db1d86627c1cb174fc0224e6d14cbc1b1d5f9d887e3fa2030dcd5bc7b61ba0d1b32f4ad5b397fff82
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Arnaud Mesureur
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Acc
|
2
|
+
|
3
|
+
Interface for the AppleCare Connect Device Enrollment Program API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'acc'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install acc
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/acc.
|
34
|
+
|
data/Rakefile
ADDED
data/acc.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acc"
|
8
|
+
spec.version = Acc::VERSION
|
9
|
+
spec.authors = ["Arnaud MESUREUR"]
|
10
|
+
spec.email = ["arnaud.mesureur@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{AppleCare Connect services interface}
|
13
|
+
spec.description = %q{Interface for the ACC Device Enrollment Program API}
|
14
|
+
spec.homepage = "https://github.com/nsarno/acc"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
|
25
|
+
spec.add_dependency "curb"
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "acc"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class ACC::BulkEnrollResponse
|
2
|
+
def initialize json_response
|
3
|
+
@response = json_response
|
4
|
+
end
|
5
|
+
|
6
|
+
def error?
|
7
|
+
error_response.present?
|
8
|
+
end
|
9
|
+
|
10
|
+
def success?
|
11
|
+
!self.error?
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_messages
|
15
|
+
error_response.collect { |e| e['errorMessage'] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def data
|
19
|
+
{
|
20
|
+
dep_transaction_id: @response['deviceEnrollmentTransactionId'],
|
21
|
+
status_message: @response['enrollDevicesResponse']['statusMessage']
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def error_response
|
28
|
+
resp = @response['enrollDeviceErrorResponse'] || ship_to_error_response
|
29
|
+
(resp.kind_of?(Array) ? resp : [resp]) if resp
|
30
|
+
end
|
31
|
+
|
32
|
+
def ship_to_error_response
|
33
|
+
@response if @response['errorMessage'].present?
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class ACC::CheckTransactionResponse
|
2
|
+
def initialize json_response
|
3
|
+
@response = json_response
|
4
|
+
end
|
5
|
+
|
6
|
+
def error?
|
7
|
+
ship_to_error? ||
|
8
|
+
error_response.present? ||
|
9
|
+
@response['statusCode'] == 'ERROR' ||
|
10
|
+
@response['statusCode'] == 'COMPLETE_WITH_ERRORS'
|
11
|
+
end
|
12
|
+
|
13
|
+
def complete?
|
14
|
+
self.success? && @response['statusCode'] == 'COMPLETE'
|
15
|
+
end
|
16
|
+
|
17
|
+
def in_progress?
|
18
|
+
in_progress_array_error? || in_progress_error?
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def in_progress_array_error?
|
23
|
+
error_response.present? && error_response.kind_of?(Array) && error_response.first['errorCode'] == 'DEP-ERR-4003'
|
24
|
+
end
|
25
|
+
|
26
|
+
def in_progress_error?
|
27
|
+
error_response.present? && error_response['errorCode'] == 'DEP-ERR-4003'
|
28
|
+
end
|
29
|
+
|
30
|
+
def success?
|
31
|
+
!self.error?
|
32
|
+
end
|
33
|
+
|
34
|
+
def error_messages
|
35
|
+
messages = [ship_to_error_message] + [single_error_message] + multiple_error_messages
|
36
|
+
messages.delete_if? { |k, v| v.blank? }
|
37
|
+
end
|
38
|
+
|
39
|
+
def data
|
40
|
+
@response
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def ship_to_error?
|
45
|
+
@response['errorCode'].present?
|
46
|
+
end
|
47
|
+
|
48
|
+
def error_response
|
49
|
+
@response['checkTransactionErrorResponse']
|
50
|
+
end
|
51
|
+
|
52
|
+
def ship_to_error_response
|
53
|
+
@response['errorMessage']
|
54
|
+
end
|
55
|
+
|
56
|
+
def single_error_message
|
57
|
+
error_response['errorMessage'] if error_response.present?
|
58
|
+
end
|
59
|
+
|
60
|
+
def multiple_error_messages
|
61
|
+
if error_response.present? && error_response.kind_of?(Array)
|
62
|
+
error_response.collect { |e| e['errorMessage'] }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/acc/service.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'curb'
|
2
|
+
|
3
|
+
class ACC::Service
|
4
|
+
def initialize
|
5
|
+
@cert_path = File.join(Rails.root, ACC::CERTIFICATE_PATH)
|
6
|
+
raise 'Invalid path to certificate' unless File.file?(@cert_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def bulk_enroll data
|
10
|
+
http_resp = request(ACC::BULK_ENROLL_URL, data)
|
11
|
+
ACC::BulkEnrollResponse.new JSON.parse(http_resp.body_str)
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_transaction_status data
|
15
|
+
http_resp = request(ACC::CHECK_TRANSACTION_URL, data)
|
16
|
+
ACC::CheckTransactionResponse.new JSON.parse(http_resp.body_str)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_order_details data
|
20
|
+
puts 'SHOW ORDER DETAILS'
|
21
|
+
http_resp = request(ACC::SHOW_ORDER_URL, data)
|
22
|
+
puts http_resp
|
23
|
+
JSON.parse(http_resp.body_str)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def request url, data
|
28
|
+
http_response = Curl::Easy.perform(url) do |req|
|
29
|
+
req.certpassword = 'Password123'
|
30
|
+
req.cert = @cert_path
|
31
|
+
req.post_body = data
|
32
|
+
req.headers['Content-Type'] = 'application/json'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/acc/version.rb
ADDED
data/lib/acc.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "acc/version"
|
2
|
+
|
3
|
+
module Acc
|
4
|
+
BULK_ENROLL_URL = 'https://api-applecareconnect-ept.apple.com/enroll-service/1.0/bulk-enroll-devices'
|
5
|
+
CHECK_TRANSACTION_URL = 'https://api-applecareconnect-ept.apple.com/enroll-service/1.0/check-transaction-status'
|
6
|
+
SHOW_ORDER_URL = 'https://api-applecareconnect-ept.apple.com/enroll-service/1.0/show-order-details'
|
7
|
+
CERTIFICATE_PATH = Rails.env.production? ? 'config/certificate.pem' : 'config/certificate.pfx'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'acc/bulk_enroll_response'
|
11
|
+
require 'acc/check_transaction_response'
|
12
|
+
require 'acc/service'
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arnaud MESUREUR
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-11 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: curb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Interface for the ACC Device Enrollment Program API
|
70
|
+
email:
|
71
|
+
- arnaud.mesureur@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- acc.gemspec
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/acc.rb
|
86
|
+
- lib/acc/bulk_enroll_response.rb
|
87
|
+
- lib/acc/check_transaction_response.rb
|
88
|
+
- lib/acc/service.rb
|
89
|
+
- lib/acc/version.rb
|
90
|
+
homepage: https://github.com/nsarno/acc
|
91
|
+
licenses: []
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: AppleCare Connect services interface
|
113
|
+
test_files: []
|