dev_mate 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 22cc40a360fbea2102ff8b9f687c3592a99ef577
4
+ data.tar.gz: 3d0294a9294237de307e027248b242d14a1f7d9e
5
+ SHA512:
6
+ metadata.gz: 75ab45fadf9069a94d26974e1fa221ae22b44b1cdbf4e6f61d3854be3e128ce90d55d175d9eeed253f35811fe60b01aeb97a6f49515c0e850dc8d804664e866f
7
+ data.tar.gz: faaf595fae80fc4e7f1744d08d26e04d4c9992137c3b0d1bce1f1982a40cef92290326bd74c0254582f795d45f8ac3c6073ff67385203634e5d822cacb65fe1b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.idea
2
+ *.gem
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at don@slack-corp.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dev_mate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Don Goodman-Wilson
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,81 @@
1
+ # dev_mate
2
+ [![Build Status](https://travis-ci.org/DEGoodmanWilson/ruby-devmate.svg?branch=master)](https://travis-ci.org/DEGoodmanWilson/ruby-devmate)
3
+ [![Coverage Status](https://coveralls.io/repos/github/DEGoodmanWilson/ruby-devmate/badge.svg?branch=master)](https://coveralls.io/github/DEGoodmanWilson/ruby-devmate?branch=master)
4
+
5
+ You use [DevMate](http://devmate.com) for selling your OS X apps, and your back-end is written in Ruby. This is the gem for you :D
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dev_mate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dev_mate
22
+
23
+ ## Usage
24
+
25
+ The DevMate API is centered on Customer objects. A customer represents, yes you guessed it, one of your customers. NB: No two customers may share the same email address.
26
+
27
+ To start working with the DevMate API, you'll need to (of course) create an account, and register your application. You will also need an API key, available from your [DevMate Dashboard](https://dashboard.devmate.com) under Company Settings > API Integration
28
+
29
+ ### Setting your API Token
30
+ ```ruby
31
+ DevMate::DevMate.SetToken('foobar')
32
+ ```
33
+
34
+ ### Creating a new customer object
35
+ ```ruby
36
+ customer = DevMate::DevMate.CreateCustomer( { "email" => "foo@example.com", "first_name" => "Jon", "last_name" => "Snow" } )
37
+ ```
38
+
39
+
40
+
41
+ ### Updating an existing customer object
42
+ ```ruby
43
+ customer["last_name"] = "Stark"
44
+ DevMate::DevMate.UpdateCustomer(customer)
45
+ ```
46
+
47
+ ### Finding a customer by Id
48
+ ```ruby
49
+ customer = DevMate::DevMate.FindCustomerById(42)
50
+ ```
51
+
52
+ ### Searching for customers by email address or name
53
+ ```ruby
54
+ customerListWithEmail = DevMate::DevMate.FindCustomerWithFilters(email: "foo@example.com")
55
+
56
+ customerListWithName = DevMate::DevMate.FindCustomerWithFilters(last_name: "Snow")
57
+ ```
58
+
59
+ ### Creating a license key for a customer
60
+
61
+ (You'll need to know the Id of the license type that you want to create)
62
+
63
+ ```ruby
64
+ license = DevMate::DevMate.CreateLicense(customer, 1)
65
+ ```
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+
71
+ 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).
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/DEGoodmanWilson/dev_mate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dev_mate"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dev_mate.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dev_mate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dev_mate"
8
+ spec.version = DevMate::VERSION
9
+ spec.authors = ["D.E. Goodman-Wilson"]
10
+ spec.email = ["degoodmanwilson@gmail.com"]
11
+
12
+ spec.summary = %q{An SDK for accessing the dev_mate API.}
13
+ spec.description = %q{Are you building an OS X app using dev_mate? Need to integrate the dev_mate API into your license server backend? Then this is the gem for you.}
14
+ spec.homepage = "https://github.com/DEGoodmanWilson/ruby-devmate"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "httparty", "~> 0.13"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.9"
27
+ spec.add_development_dependency "coveralls"
28
+ end
data/lib/dev_mate.rb ADDED
@@ -0,0 +1,208 @@
1
+ require "dev_mate/version"
2
+ require "json"
3
+ require "httparty"
4
+
5
+ module DevMate
6
+
7
+ class BadRequestError < StandardError
8
+ end
9
+
10
+ class UnauthorizedError < StandardError
11
+ end
12
+
13
+ class ConflictError < StandardError
14
+ end
15
+
16
+ class NotFoundError < StandardError
17
+ end
18
+
19
+ class UnknownError < StandardError
20
+ end
21
+
22
+ class DevMate
23
+ include HTTParty
24
+
25
+ base_uri 'https://public-api.devmate.com/v2'
26
+
27
+ def self.SetToken(token)
28
+ @@token = token
29
+ @@auth_header = "Token #{token}"
30
+ end
31
+
32
+ def self.Token
33
+ @@token
34
+ end
35
+
36
+ def self.CreateCustomer(email, last_name: nil, first_name: nil, note: nil)
37
+ data = { :email => email }
38
+ data[last_name] = last_name if last_name
39
+ data[first_name] = first_name if first_name
40
+ data[note] = note if note
41
+ body = { :data => data }
42
+
43
+ raise UnauthorizedError, "Please specify a token with SetToken()" unless defined? @@token
44
+
45
+ options = { :body => body.to_json, :headers => { "Authorization" => @@auth_header } }
46
+ response = self.post('/customers/', options)
47
+
48
+ #TODO handle timeouts!
49
+ response_object = JSON.parse response.body
50
+
51
+ unless response.code == 201
52
+ #sad path
53
+ errors = response_object["errors"]
54
+
55
+ case response.code
56
+ when 400
57
+ raise BadRequestError, "#{errors[0]["title"]} #{errors[0]["detail"]}"
58
+ when 401
59
+ raise UnauthorizedError, errors[0]["title"]
60
+ when 409
61
+ raise ConflictError, "#{errors[0]["title"]} #{errors[0]["detail"]}"
62
+ else
63
+ raise UnknownError
64
+ end
65
+ end
66
+
67
+ # return response.body on success
68
+ response_object = JSON.parse response.body
69
+ return response_object['data']
70
+ end
71
+
72
+ def self.FindCustomerById(id)
73
+
74
+ raise UnauthorizedError, "Please specify a token with SetToken()" unless defined? @@token
75
+
76
+ response = self.get("/customers/#{id}", :headers => { "Authorization" => @@auth_header })
77
+
78
+ #TODO handle timeouts!
79
+ response_object = JSON.parse response.body
80
+
81
+ unless response.code == 201
82
+ #sad path
83
+ errors = response_object["errors"]
84
+
85
+ case response.code
86
+ when 401
87
+ raise UnauthorizedError, errors[0]["title"]
88
+ when 404
89
+ return nil
90
+ end
91
+ end
92
+
93
+ # return response.body on success
94
+ response_object = JSON.parse response.body
95
+ return response_object['data']
96
+ end
97
+
98
+ def self.FindCustomerWithFilters(email: nil, first_name: nil, last_name: nil, license_key: nil, identifier: nil, order_id: nil, activation_id: nil, invoice: nil, offset: nil, limit: nil, with: nil)
99
+
100
+ query = {}
101
+ query["filter[email]"] = email if email
102
+ query["filter[first_name]"] = first_name if first_name
103
+ query["filter[last_name]"] = last_name if last_name
104
+ query["filter[license_key]"] = license_key if license_key
105
+ query["filter[identifier]"] = identifier if identifier
106
+ query["filter[order_id]"] = order_id if order_id
107
+ query["filter[activation_id]"] = activation_id if activation_id
108
+ query["filter[invoice]"] = invoice if invoice
109
+ query["offset"] = offset if offset
110
+ query["limit"] = limit if limit
111
+ query["with"] = with if with
112
+
113
+ raise UnauthorizedError, "Please specify a token with SetToken()" unless defined? @@token
114
+
115
+ response = self.get("/customers", :query => query, :headers => { "Authorization" => @@auth_header })
116
+
117
+ #TODO handle timeouts!
118
+ response_object = JSON.parse response.body
119
+
120
+ unless response.code == 201
121
+ #sad path
122
+ errors = response_object["errors"]
123
+
124
+ case response.code
125
+ when 401
126
+ raise UnauthorizedError, errors[0]["title"]
127
+ when 404
128
+ return []
129
+ end
130
+ end
131
+
132
+ # return response.body on success
133
+ response_object = JSON.parse response.body
134
+ return response_object['data']
135
+ end
136
+
137
+ def self.UpdateCustomer(customer)
138
+
139
+ return nil unless customer['id']
140
+
141
+ id = customer['id']
142
+
143
+ new_customer = {}
144
+ new_customer[:email] = customer["email"] if customer["email"]
145
+ new_customer[:first_name] = customer["first_name"] if customer["first_name"]
146
+ new_customer[:last_name] = customer["last_name"] if customer["last_name"]
147
+ new_customer[:notes] = customer["notes"] if customer["notes"]
148
+
149
+ data = { :data => new_customer }
150
+
151
+ raise UnauthorizedError, "Please specify a token with SetToken()" unless defined? @@token
152
+
153
+ response = self.put("/customers/#{id}", :body => data.to_json, :headers => { "Authorization" => @@auth_header })
154
+
155
+ #TODO handle timeouts!
156
+ response_object = JSON.parse response.body
157
+
158
+ unless response.code == 201
159
+ #sad path
160
+ errors = response_object["errors"]
161
+
162
+ case response.code
163
+ when 400
164
+ raise BadRequestError, "#{errors[0]["title"]} #{errors[0]["detail"]}"
165
+ when 401
166
+ raise UnauthorizedError, errors[0]["title"]
167
+ when 404
168
+ raise NotFoundError, "#{errors[0]["title"]} #{errors[0]["detail"]}"
169
+ when 409
170
+ raise ConflictError, "#{errors[0]["title"]} #{errors[0]["detail"]}"
171
+ end
172
+ end
173
+
174
+ # return response.body on success
175
+ response_object = JSON.parse response.body
176
+ return response_object['data']
177
+ end
178
+
179
+ def self.CreateLicense(customer, licenseId)
180
+ id = customer["id"]
181
+ data = { :data => { :license_type_id => licenseId } }
182
+
183
+ raise UnauthorizedError, "Please specify a token with SetToken()" unless defined? @@token
184
+
185
+ response = self.post("/customers/#{id}/licenses", :body => data.to_json, :headers => { "Authorization" => @@auth_header })
186
+
187
+ #TODO handle timeouts!
188
+ response_object = JSON.parse response.body
189
+
190
+ unless response.code == 201
191
+ #sad path
192
+ errors = response_object["errors"]
193
+
194
+ case response.code
195
+ when 400
196
+ raise BadRequestError, "#{errors[0]["title"]} #{errors[0]["detail"]}"
197
+ when 401
198
+ raise UnauthorizedError, errors[0]["title"]
199
+ end
200
+ end
201
+
202
+ # return response.body on success
203
+ response_object = JSON.parse response.body
204
+ return response_object['data']
205
+ end
206
+
207
+ end # class
208
+ end # module
@@ -0,0 +1,3 @@
1
+ module DevMate
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev_mate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - D.E. Goodman-Wilson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '5.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Are you building an OS X app using dev_mate? Need to integrate the dev_mate
84
+ API into your license server backend? Then this is the gem for you.
85
+ email:
86
+ - degoodmanwilson@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .travis.yml
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - dev_mate.gemspec
101
+ - lib/dev_mate.rb
102
+ - lib/dev_mate/version.rb
103
+ homepage: https://github.com/DEGoodmanWilson/ruby-devmate
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.14.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: An SDK for accessing the dev_mate API.
127
+ test_files: []