aptible-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de97a55e4f0426413608ac2336bb10152a27d585
4
+ data.tar.gz: dae4ae1d019a5c468cb424d26329b19f5108cd10
5
+ SHA512:
6
+ metadata.gz: 7edc220e803b9befb996aa0ded1c1edd956f0921ac2e9fbe613ed8976073a84ae47f8c96feddd4527d34bde4a7e48e89186fb1301264e6adf953faac4b082e59
7
+ data.tar.gz: 26f4455b8a8e03aedc70913dad6ae69c848530216103918cc8c768e7680253b443e3b497630def96ff39193239313c0492b6d15894fe055db479ee57faf48934
data/.gitignore ADDED
@@ -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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'oauth2', github: 'fancyremarker/oauth2', branch: 'aptible'
4
+ gem 'hyperresource', github: 'fancyremarker/hyperresource', branch: 'aptible'
5
+
6
+ # Specify your gem's dependencies in aptible-api.gemspec
7
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aptible, Inc.
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.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # ![](https://raw.github.com/aptible/straptible/master/lib/straptible/rails/templates/public.api/icon-60px.png) Aptible::Api
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/aptible-api.png)](https://rubygems.org/gems/aptible-api)
4
+ [![Build Status](https://travis-ci.org/aptible/aptible-api-ruby.png?branch=master)](https://travis-ci.org/aptible/aptible-api-ruby)
5
+ [![Dependency Status](https://gemnasium.com/aptible/aptible-api-ruby.png)](https://gemnasium.com/aptible/aptible-api-ruby)
6
+
7
+ Ruby client for [api.aptible.com](https://api.aptible.com/). Aptible's API server is built on top of [HAL+JSON](http://tools.ietf.org/html/draft-kelly-json-hal-06), and so this client is just a thin layer on top of the [HyperResource](https://github.com/gamache/hyperresource) gem.
8
+
9
+ ## Installation
10
+
11
+ Add the following lines to your application's Gemfile.
12
+
13
+ gem 'aptible-api'
14
+ gem 'hyperresource', github: 'fancyremarker/hyperresource', branch: 'aptible'
15
+
16
+ The forked version of the HyperResource gem is necessary until [gamache/hyperresource#19](https://github.com/gamache/hyperresource/pull/19) is merged.
17
+
18
+ And then run `bundle install`.
19
+
20
+ ## Usage
21
+
22
+ First, get a token:
23
+
24
+ ```ruby
25
+ token = Aptible::Auth::Token.new(email: 'user0@example.com', password: 'password')
26
+ ```
27
+
28
+ Then, initialize a client:
29
+ ```ruby
30
+ api = Aptible::Api::Client.new(token: token)
31
+ ```
32
+
33
+ From here, you can interact with the Authorization API however you wish:
34
+
35
+ ```ruby
36
+ api.get.clients.count
37
+ # => 4
38
+ api.get.clients.first.name
39
+ # => "Client 0"
40
+ client = api.get.clients.create(name: 'Dogeclient')
41
+ client.href
42
+ # => "http://localhost:4000/clients/60765b69-ffd8-4762-b9d2-96354ddb16f9"
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ | Parameter | Description | Default |
48
+ | --------- | ----------- | --------------- |
49
+ | `root_url` | Root URL of the authorization server | `https://api.aptible.com` |
50
+
51
+ To point the client at a different authorization server (e.g., during development), add the following to your application's initializers:
52
+
53
+ ```ruby
54
+ Aptible::Api.configure do |config|
55
+ config.root_url = 'http://some.other.url'
56
+ end
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork the project.
62
+ 1. Commit your changes, with specs.
63
+ 1. Ensure that your code passes specs (`rake spec`) and meets Aptible's Ruby style guide (`rake rubocop`).
64
+ 1. Create a new pull request on GitHub.
65
+
66
+ ## Copyright and License
67
+
68
+ MIT License, see [LICENSE](LICENSE.md) for details.
69
+
70
+ Copyright (c) 2013 [Aptible](https://www.aptible.com), Frank Macreery, and contributors.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'aptible/tasks'
4
+ Aptible::Tasks.load_tasks
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'English'
6
+ require 'aptible/api/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'aptible-api'
10
+ spec.version = Aptible::Api::VERSION
11
+ spec.authors = ['Frank Macreery']
12
+ spec.email = ['frank@macreery.com']
13
+ spec.description = %q{Ruby client for api.aptible.com}
14
+ spec.summary = %q{Ruby client for api.aptible.com}
15
+ spec.homepage = 'https://github.com/aptible/aptible-api'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($RS)
19
+ spec.test_files = spec.files.grep(/^spec\//)
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'gem_config'
23
+ spec.add_dependency 'hyperresource'
24
+ spec.add_dependency 'aptible-auth'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'aptible-tasks', '>= 0.2.0'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec', '~> 2.0'
30
+ spec.add_development_dependency 'pry'
31
+ end
@@ -0,0 +1,14 @@
1
+ require 'aptible/api/version'
2
+ require 'aptible/api/client'
3
+
4
+ require 'gem_config'
5
+
6
+ module Aptible
7
+ module Api
8
+ include GemConfig::Base
9
+
10
+ with_configuration do
11
+ has :root_url, classes: [String], default: 'https://api.aptible.com'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'hyperresource'
2
+
3
+ module Aptible
4
+ module Api
5
+ class Client < HyperResource
6
+ attr_accessor :token, :config
7
+
8
+ def initialize(options = {})
9
+ unless options.is_a?(Hash)
10
+ fail ArgumentError, 'Call Aptible::Api::Client.new with a Hash'
11
+ end
12
+ self.token = options[:token]
13
+
14
+ options[:root] ||= config.root_url
15
+ options[:headers] ||= { 'Content-Type' => 'application/json' }
16
+ options[:headers].merge!(
17
+ 'Authorization' => "Bearer #{bearer_token}"
18
+ ) if options[:token]
19
+
20
+ super(options)
21
+ end
22
+
23
+ def bearer_token
24
+ # REVIEW: Should we really allow any token type here?
25
+ case token
26
+ when Aptible::Auth::Token then token.access_token
27
+ when Fridge::AccessToken then token.to_s
28
+ when String then token
29
+ end
30
+ end
31
+
32
+ def config
33
+ @config ||= Aptible::Api.configuration
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Aptible
2
+ module Api
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::Api::Client do
4
+ describe '#initialize' do
5
+ it 'should be a HyperResource instance' do
6
+ expect(subject).to be_a HyperResource
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::Api do
4
+ it 'should have a configurable root_url' do
5
+ config = described_class.configuration
6
+ expect(config).to be_a GemConfig::Configuration
7
+ expect(config.root_url).to eq 'https://api.aptible.com'
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ # Load shared spec files
5
+ Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
6
+ require file
7
+ end
8
+
9
+ # Require library up front
10
+ require 'aptible/api'
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aptible-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Macreery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_config
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hyperresource
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: aptible-auth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aptible-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.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.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Ruby client for api.aptible.com
126
+ email:
127
+ - frank@macreery.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE.md
137
+ - README.md
138
+ - Rakefile
139
+ - aptible-api.gemspec
140
+ - lib/aptible/api.rb
141
+ - lib/aptible/api/client.rb
142
+ - lib/aptible/api/version.rb
143
+ - spec/aptible/api/client_spec.rb
144
+ - spec/aptible/api_spec.rb
145
+ - spec/spec_helper.rb
146
+ homepage: https://github.com/aptible/aptible-api
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.2.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Ruby client for api.aptible.com
170
+ test_files:
171
+ - spec/aptible/api/client_spec.rb
172
+ - spec/aptible/api_spec.rb
173
+ - spec/spec_helper.rb