packethost 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ require 'active_support/concern'
2
+
3
+ module Packet
4
+ module Entity
5
+ module Timestamps
6
+ extend ActiveSupport::Concern
7
+
8
+ DEFAULT_TIMESTAMPS = [:created_at, :updated_at].freeze
9
+
10
+ module ClassMethods
11
+ def has_timestamps(timestamps = DEFAULT_TIMESTAMPS)
12
+ timestamps.each { |timestamp| casts(timestamp, ->(value) { Time.parse(value) }) }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'active_support/concern'
2
+ require 'packet/entity/base'
3
+ require 'packet/entity/associations'
4
+ require 'packet/entity/finders'
5
+ require 'packet/entity/persistence'
6
+ require 'packet/entity/serialization'
7
+ require 'packet/entity/timestamps'
8
+
9
+ module Packet
10
+ module Entity
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ include(Base)
15
+ include(Associations)
16
+ include(Finders)
17
+ include(Persistence)
18
+ include(Serialization)
19
+ include(Timestamps)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module Packet
2
+ class Error < StandardError; end
3
+ class NotFound < Error; end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Packet
2
+ class Facility
3
+ include Entity
4
+
5
+ attr_accessor :name
6
+ attr_accessor :code
7
+ attr_accessor :features
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Packet
4
+ class GlobalIDLocator
5
+ CLASS_MAP = {
6
+ 'Instance' => :device
7
+ }.freeze
8
+
9
+ def initialize(client)
10
+ @client = client || Packet::Client.instance
11
+ end
12
+
13
+ def locate(gid)
14
+ @client.send method_for_model_name(gid.model_name), gid.model_id
15
+ end
16
+
17
+ private
18
+
19
+ def method_for_model_name(name)
20
+ if CLASS_MAP.key?(name)
21
+ CLASS_MAP[name]
22
+ else
23
+ name.underscore
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Packet
2
+ class OperatingSystem
3
+ include Entity
4
+
5
+ attr_accessor :slug
6
+ attr_accessor :name
7
+ attr_accessor :distro
8
+ attr_accessor :version
9
+ attr_accessor :provisionable_on
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Packet
2
+ class Plan
3
+ include Entity
4
+
5
+ attr_accessor :slug
6
+ attr_accessor :name
7
+ attr_accessor :description
8
+ attr_accessor :line
9
+ attr_accessor :specs
10
+ attr_accessor :pricing
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Packet
2
+ class Project
3
+ include Entity
4
+
5
+ attr_accessor :name
6
+
7
+ has_many :devices
8
+ has_timestamps
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Packet
2
+ class SshKey
3
+ include Entity
4
+
5
+ attr_accessor :label
6
+ attr_accessor :key
7
+
8
+ has_timestamps
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module Packet
2
+ class User
3
+ include Entity
4
+
5
+ attr_accessor :first_name
6
+ attr_accessor :last_name
7
+ # attr_accessor :full_name
8
+ attr_accessor :email
9
+ attr_accessor :avatar_url
10
+ attr_accessor :timezone
11
+
12
+ has_timestamps
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Packet
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/packet.rb ADDED
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+
3
+ require 'packet/client'
4
+ require 'packet/configuration'
5
+ require 'packet/errors'
6
+ require 'packet/version'
7
+
8
+ module Packet
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield(configuration)
15
+ reset_client!
16
+ true
17
+ end
18
+
19
+ def self.reset!
20
+ @configuration = Configuration.new
21
+ reset_client!
22
+ end
23
+
24
+ def self.client
25
+ @client ||= Packet::Client.new
26
+ end
27
+
28
+ private
29
+
30
+ def self.reset_client!
31
+ @client = nil
32
+ end
33
+
34
+ def self.respond_to_missing?(method_name, include_private = false)
35
+ client.respond_to?(method_name, include_private)
36
+ end if RUBY_VERSION >= '1.9'
37
+
38
+ def self.respond_to?(method_name, include_private = false)
39
+ client.respond_to?(method_name, include_private) || super
40
+ end if RUBY_VERSION < '1.9'
41
+
42
+ def self.method_missing(method_name, *args, &block)
43
+ if client.respond_to?(method_name)
44
+ client.send(method_name, *args, &block)
45
+ else
46
+ super
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'packet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'packethost'
8
+ spec.version = Packet::VERSION
9
+ spec.authors = ['Jake Bell', 'Emiliano Jankowski', 'Andrew Hodges']
10
+ spec.email = %w(jake@packet.net emiliano@packet.net andy@packet.net)
11
+
12
+ spec.summary = %q{Ruby client for the Packet API}
13
+ spec.description = %q{Ruby client for the Packet API}
14
+ spec.homepage = 'https://www.packet.net'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = %w(lib)
18
+ spec.bindir = 'bin'
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+
21
+ spec.add_dependency 'activesupport', '~> 4.2'
22
+ spec.add_dependency 'faraday', '>= 0.9.0'
23
+ spec.add_dependency 'faraday_middleware', '>= 0.9.0'
24
+
25
+ spec.add_development_dependency 'rake', '~> 0'
26
+ spec.add_development_dependency 'rspec', '~> 3'
27
+ spec.add_development_dependency 'webmock', '~> 1.20'
28
+ spec.add_development_dependency 'rdoc', '~> 4'
29
+ spec.add_development_dependency 'bundler', '~> 1.0'
30
+ spec.add_development_dependency 'simplecov', '~> 0'
31
+ spec.add_development_dependency 'rubocop', '~> 0'
32
+ spec.add_development_dependency 'sinatra', '~> 1.4'
33
+ spec.add_development_dependency 'pry'
34
+ end
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: packethost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jake Bell
8
+ - Emiliano Jankowski
9
+ - Andrew Hodges
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-01-11 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '4.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '4.2'
29
+ - !ruby/object:Gem::Dependency
30
+ name: faraday
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: faraday_middleware
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.9.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '3'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '3'
85
+ - !ruby/object:Gem::Dependency
86
+ name: webmock
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.20'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.20'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rdoc
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '4'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '4'
113
+ - !ruby/object:Gem::Dependency
114
+ name: bundler
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '1.0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '1.0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: simplecov
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: rubocop
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: sinatra
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '1.4'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: '1.4'
169
+ - !ruby/object:Gem::Dependency
170
+ name: pry
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ description: Ruby client for the Packet API
184
+ email:
185
+ - jake@packet.net
186
+ - emiliano@packet.net
187
+ - andy@packet.net
188
+ executables: []
189
+ extensions: []
190
+ extra_rdoc_files: []
191
+ files:
192
+ - ".gitignore"
193
+ - ".rspec"
194
+ - ".rubocop.yml"
195
+ - ".travis.yml"
196
+ - CHANGELOG.md
197
+ - Gemfile
198
+ - LICENSE
199
+ - README.md
200
+ - Rakefile
201
+ - lib/packet.rb
202
+ - lib/packet/client.rb
203
+ - lib/packet/client/devices.rb
204
+ - lib/packet/client/facilities.rb
205
+ - lib/packet/client/operating_systems.rb
206
+ - lib/packet/client/plans.rb
207
+ - lib/packet/client/projects.rb
208
+ - lib/packet/client/ssh_keys.rb
209
+ - lib/packet/client/users.rb
210
+ - lib/packet/configuration.rb
211
+ - lib/packet/device.rb
212
+ - lib/packet/entity.rb
213
+ - lib/packet/entity/associations.rb
214
+ - lib/packet/entity/base.rb
215
+ - lib/packet/entity/finders.rb
216
+ - lib/packet/entity/persistence.rb
217
+ - lib/packet/entity/serialization.rb
218
+ - lib/packet/entity/timestamps.rb
219
+ - lib/packet/errors.rb
220
+ - lib/packet/facility.rb
221
+ - lib/packet/global_id.rb
222
+ - lib/packet/operating_system.rb
223
+ - lib/packet/plan.rb
224
+ - lib/packet/project.rb
225
+ - lib/packet/ssh_key.rb
226
+ - lib/packet/user.rb
227
+ - lib/packet/version.rb
228
+ - packethost.gemspec
229
+ homepage: https://www.packet.net
230
+ licenses: []
231
+ metadata: {}
232
+ post_install_message:
233
+ rdoc_options: []
234
+ require_paths:
235
+ - lib
236
+ required_ruby_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ required_rubygems_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ requirements: []
247
+ rubyforge_project:
248
+ rubygems_version: 2.4.5.1
249
+ signing_key:
250
+ specification_version: 4
251
+ summary: Ruby client for the Packet API
252
+ test_files: []