one_one 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: 5362ff5cc64c9a7f62fe2eaa96239736342229b1
4
+ data.tar.gz: acac0345f77d76c465e889f758987efb699fd978
5
+ SHA512:
6
+ metadata.gz: e32585b4599d9a78d71f66a916dd030ba9a5a1f98eda4968ec5736ea6a3483106cf47f28371d1725aeafa67d13b499d57e8b01be307de42f64cd78e23110a85d
7
+ data.tar.gz: d80abe069f2ff52df3716bbec9c484dbf9b2d72f5920e3d6baf61d06f7820273abf11974aef0f0ba7e89372c3964aabf248ea9b904261976b3bf0ae24a28bc75
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in one_one.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Connor Atherton
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,19 @@
1
+ # OneOne
2
+
3
+ A ruby client for the 1and1 cloud API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'one_one'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install one_one
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "one_one"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,65 @@
1
+ require 'faraday'
2
+ require 'pry'
3
+
4
+ module OneOne
5
+ class Client
6
+ API_VERSION = 1
7
+ API_URL = 'https://cloudpanel-api.1and1.com'
8
+
9
+ attr_reader :token
10
+
11
+ def initialize(options)
12
+ @token = options[:token]
13
+ end
14
+
15
+ def connection
16
+ Faraday.new(connection_options) do |req|
17
+ req.adapter :net_http
18
+ end
19
+ end
20
+
21
+ # This is used to lazy-load resources.
22
+ # It is stored in the @resources instance
23
+ # variable when a caller requests the resource.
24
+ def self.resources
25
+ {
26
+ servers: ServerResource,
27
+ images: ImageResource,
28
+ server_appliances: ServerApplianceResource,
29
+ firewall_policies: FirewallPolicyResource
30
+ }
31
+ end
32
+
33
+ def resources
34
+ @resources ||= {}
35
+ end
36
+
37
+ # This attaches resources to the client
38
+ # Resources map to a specific model
39
+ def method_missing(name, *args, &block)
40
+ if self.class.resources.keys.include?(name)
41
+ resources[name] ||= self.class.resources[name].new(connection: connection)
42
+ resources[name]
43
+ else
44
+ super
45
+ end
46
+ end
47
+
48
+ def token_valid?
49
+ res = connection.get('/v1/')
50
+ binding.pry
51
+ end
52
+
53
+ private
54
+
55
+ def connection_options
56
+ {
57
+ url: API_URL,
58
+ headers: {
59
+ content_type: 'application/json',
60
+ 'x-token' => token
61
+ }
62
+ }
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ module OneOne
2
+ class FirewallPolicyMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping FirewallPolicy
7
+
8
+ property :id, scopes: [:read]
9
+ property :name, scopes: [:read, :create]
10
+ property :description, scopes: [:read, :create]
11
+ property :state, scopes: [:read]
12
+ property :creation_date, scopes: [:read]
13
+ property :default, scopes: [:read]
14
+ property :rules, scopes: [:read, :create]
15
+ property :server_ips, scopes: [:read]
16
+ property :cloudpanel_id, scopes: [:read]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module OneOne
2
+ class ImageMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping Image
7
+
8
+ property :id, scopes: [:read]
9
+ property :name, scopes: [:read]
10
+ property :os_family, scopes: [:read]
11
+ property :os, scopes: [:read]
12
+ property :os_version, scopes: [:read]
13
+ property :os_image_type, scopes: [:read]
14
+ property :min_hdd_size, scopes: [:read]
15
+ property :state, scopes: [:read]
16
+ property :creation_date, scopes: [:read]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module OneOne
2
+ class ServerApplianceMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping ServerAppliance
7
+
8
+ property :id, scopes: [:read]
9
+ property :name, scopes: [:read]
10
+ property :os_family, scopes: [:read]
11
+ property :os, scopes: [:read]
12
+ property :os_version, scopes: [:read]
13
+ property :architecture, scopes: [:read]
14
+ property :os_image_type, scopes: [:read]
15
+ property :type, scopes: [:read]
16
+ property :min_hdd_size, scopes: [:read]
17
+ property :licenses, scopes: [:read]
18
+ property :automatic_installation, scopes: [:read]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module OneOne
2
+ class ServerMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping Server
7
+
8
+ property :id, scopes: [:read]
9
+ property :description, scopes: [:read, :create]
10
+ property :name, scopes: [:read, :create]
11
+ property :first_password, scopes: [:read]
12
+ property :status, scopes: [:read]
13
+ property :hardware, scopes: [:read, :create]
14
+ property :creation_date, scopes: [:read]
15
+ property :appliance_id, scopes: [:read, :create]
16
+ property :ips, scopes: [:read]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ require 'virtus'
2
+
3
+ module OneOne
4
+ class Base
5
+ include Virtus.model
6
+
7
+ # Shared by all json responses
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module OneOne
2
+ class FirewallPolicy < Base
3
+ attribute :id
4
+ attribute :name
5
+ attribute :description
6
+ attribute :state
7
+ attribute :creation_date
8
+ attribute :default
9
+ attribute :rules
10
+ attribute :server_ips
11
+ attribute :cloudpanel_id
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module OneOne
2
+ class Image < Base
3
+ attribute :id
4
+ attribute :name
5
+ attribute :os_family
6
+ attribute :os
7
+ attribute :os_version
8
+ attribute :os_image_type
9
+ attribute :min_hdd_size
10
+ attribute :state
11
+ attribute :creation_date
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module OneOne
2
+ class Server < Base
3
+ attribute :id
4
+ attribute :name
5
+ attribute :description
6
+ attribute :first_password
7
+ attribute :status
8
+ attribute :hardware
9
+ attribute :creation_date
10
+ attribute :ips
11
+ attribute :description
12
+ attribute :appliance_id
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module OneOne
2
+ class ServerAppliance < Base
3
+ attribute :id
4
+ attribute :name
5
+ attribute :os_family
6
+ attribute :os
7
+ attribute :os_version
8
+ attribute :architecture
9
+ attribute :os_image_type
10
+ attribute :type
11
+ attribute :min_hdd_size
12
+ attribute :licenses
13
+ attribute :automatic_installation
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module OneOne
2
+ class FirewallPolicyResource < ResourceKit::Resource
3
+ resources do
4
+ action :all, 'GET /api/v1/firewall_policies' do
5
+ handler(200) do |response|
6
+ FirewallPolicyMapping.extract_collection(response.body, :read)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module OneOne
2
+ class ImageResource < ResourceKit::Resource
3
+ resources do
4
+ default_handler do |response|
5
+ fail "Unexpected response status #{response.status}... #{response.body}"
6
+ end
7
+
8
+ action :all, 'GET /v1/images' do
9
+ handler(200) do |response|
10
+ ImageMapping.extract_collection(response.body, :read)
11
+ end
12
+ end
13
+
14
+ action :find, 'GET /v1/images/:id' do
15
+ handler(200) do |response|
16
+ ServerMapping.extract_single(response.body, :read)
17
+ end
18
+ end
19
+
20
+ # TODO create
21
+ action :create, 'POST /v1/images' do
22
+ handler(200) do |response|
23
+ ServerMapping.extract_single(response.body, :read)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module OneOne
2
+ class ServerApplianceResource < ResourceKit::Resource
3
+ resources do
4
+ default_handler do |response|
5
+ fail "Unexpected response status #{response.status}... #{response.body}"
6
+ end
7
+
8
+ action :all, 'GET /v1/server_appliances' do
9
+ handler(200) do |response|
10
+ ServerApplianceMapping.extract_collection(response.body, :read)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module OneOne
2
+ class ServerResource < ResourceKit::Resource
3
+ resources do
4
+ default_handler do |response|
5
+ fail "Unexpected response status #{response.status}... #{response.body}"
6
+ end
7
+
8
+ action :all, 'GET /v1/servers' do
9
+ handler(200) do |response|
10
+ ServerMapping.extract_collection(response.body, :read)
11
+ end
12
+ end
13
+
14
+ action :find, 'GET /v1/servers/:id' do
15
+ handler(200) do |response|
16
+ ServerMapping.extract_single(response.body, :read)
17
+ end
18
+ end
19
+
20
+ action :create, 'POST /v1/servers' do
21
+ body { |object| ServerMapping.representation_for(:create, object) }
22
+ handler(202) do |response|
23
+ ServerMapping.extract_single(response.body, :read)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module OneOne
2
+ VERSION = '0.1.0'
3
+ end
data/lib/one_one.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'one_one/version'
2
+ require 'resource_kit'
3
+ require 'kartograph'
4
+ require 'active_support/all'
5
+
6
+ module OneOne
7
+ # client
8
+ autoload :Client, 'one_one/client'
9
+
10
+ # models
11
+ autoload :Base, 'one_one/models/base'
12
+ autoload :Server, 'one_one/models/server'
13
+ autoload :Image, 'one_one/models/image'
14
+ autoload :ServerAppliance, 'one_one/models/server_appliance'
15
+ autoload :FirewallPolicy, 'one_one/models/firewall_policy'
16
+
17
+ # mappings
18
+ autoload :ServerMapping, 'one_one/mappings/server_mapping'
19
+ autoload :ImageMapping, 'one_one/mappings/image_mapping'
20
+ autoload :ServerApplianceMapping, 'one_one/mappings/server_appliance_mapping'
21
+ autoload :FirewallPolicyMapping, 'one_one/mappings/firewall_policy_mapping'
22
+
23
+ # resources
24
+ autoload :ServerResource, 'one_one/resources/server_resource'
25
+ autoload :ImageResource, 'one_one/resources/image_resource'
26
+ autoload :ServerApplianceResource, 'one_one/resources/server_appliance_resource'
27
+ autoload :FirewallPolicyResource, 'one_one/resources/firewall_policy_resource'
28
+ end
data/one_one.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'one_one/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "one_one"
8
+ spec.version = OneOne::VERSION
9
+ spec.authors = ["Connor Atherton"]
10
+ spec.email = ["connor@bitnami.com"]
11
+
12
+ spec.summary = %q{A client library for the 1and1 cloud api}
13
+ spec.description = %q{A client library for the 1and1 cloud api}
14
+ spec.homepage = "https://github.com/ConnorAtherton/one_one"
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_development_dependency 'bundler', '~> 1.8'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'pry'
25
+
26
+ spec.add_dependency 'faraday'
27
+ spec.add_dependency 'kartograph'
28
+ spec.add_dependency 'virtus'
29
+ spec.add_dependency 'resource_kit'
30
+ spec.add_dependency 'activesupport'
31
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: one_one
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Connor Atherton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-01 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
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: pry
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: faraday
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
+ - !ruby/object:Gem::Dependency
70
+ name: kartograph
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: virtus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
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: resource_kit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A client library for the 1and1 cloud api
126
+ email:
127
+ - connor@bitnami.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - lib/one_one.rb
143
+ - lib/one_one/client.rb
144
+ - lib/one_one/mappings/firewall_policy_mapping.rb
145
+ - lib/one_one/mappings/image_mapping.rb
146
+ - lib/one_one/mappings/server_appliance_mapping.rb
147
+ - lib/one_one/mappings/server_mapping.rb
148
+ - lib/one_one/models/base.rb
149
+ - lib/one_one/models/firewall_policy.rb
150
+ - lib/one_one/models/image.rb
151
+ - lib/one_one/models/server.rb
152
+ - lib/one_one/models/server_appliance.rb
153
+ - lib/one_one/resources/firewall_policy_resource.rb
154
+ - lib/one_one/resources/image_resource.rb
155
+ - lib/one_one/resources/server_appliance_resource.rb
156
+ - lib/one_one/resources/server_resource.rb
157
+ - lib/one_one/version.rb
158
+ - one_one.gemspec
159
+ homepage: https://github.com/ConnorAtherton/one_one
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.2.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: A client library for the 1and1 cloud api
183
+ test_files: []