linodeapi 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 613ee064aa8a8581a6d3c44d7b2b654ecf006ae3
4
- data.tar.gz: bc5aafb0308006830ffd6a90d1ba642a9ab7a282
3
+ metadata.gz: d2b6266cebf4ba879b7b79560958046dcfbeef85
4
+ data.tar.gz: e4f7be859b3b424d4023d228a2bf465652b27c8d
5
5
  SHA512:
6
- metadata.gz: b83e57e4909a32e9aa9e1c4e876e808e6589813edb4f3b94167d3bc0b8b81f1fb35ea26e96d97221bc360a3af477d6770358b37cb67a5785564706976ac96658
7
- data.tar.gz: fa56efc343ff4c6ca9aee7642e23f3a967901e5b1f35a8b6ecca8e800790a6cdf5612c33f84c66de302a0856879a772965ca686a490f77ba4221a5e27b06d76b
6
+ metadata.gz: 9c0400892e248bf04836685ea695ed2415dd5c38b39fd12f55028685a178d3cc6891ac99c07a6c730b2ada07c19058a86dad965bfc3ad472c19a7cb0df65586c
7
+ data.tar.gz: a3645671fea6219314385c06f922eb957796460beb4f864a8df72700e2210d306dd699d39c00079791fb7b3546256284d6337b386180b3f2d942642bfe3bd1a6
data/.prospectus ADDED
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ item do
4
+ expected do
5
+ static
6
+ set 'green'
7
+ end
8
+
9
+ actual do
10
+ gemnasium
11
+ slug 'akerl/linodeapi'
12
+ end
13
+
14
+ deps do
15
+ YAML.load(`./dev/cache_spec.rb --noop`).each do |item_name, (old, new)|
16
+ item do
17
+ name "api.spec.#{item_name}"
18
+
19
+ expected do
20
+ static
21
+ set new
22
+ end
23
+
24
+ actual do
25
+ static
26
+ set old
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.0.1 / 2016-07-01
2
+
3
+ * [FEATURE] Expose LinodeAPI.spec_version
4
+
1
5
  # 1.0.0 / 2015-01-19
2
6
 
3
7
  * [ENHANCEMENT] Stabilized API
data/dev/cache_spec.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'mercenary'
3
4
  require 'linodeapi'
4
5
  require 'yaml'
6
+ require 'digest'
5
7
 
6
- SPEC_FILE = $ARGV.first || 'dev/spec.yml'
8
+ SPEC_FILE = 'dev/spec.yml'.freeze
9
+ VERSION_FILE = File.join(File.dirname(SPEC_FILE), 'version')
7
10
 
8
11
  def parse_node(node)
9
- return clean_node(node) if node[:type] == :call
12
+ return clean_node(node.dup) if node[:type] == :call
10
13
  Hash[node[:subs].sort.map { |k, v| [k.to_s, parse_node(v)] }]
11
14
  end
12
15
 
@@ -20,6 +23,38 @@ def hash_to_array(hash)
20
23
  hash.to_a.sort.map { |x| Hash[x.first.to_s, hash_to_array(x.last)] }
21
24
  end
22
25
 
23
- result = parse_node(LinodeAPI.spec)
26
+ def write_changes
27
+ File.open(SPEC_FILE, 'w') { |fh| fh << YAML.dump(parse_node(LinodeAPI.spec)) }
28
+ File.open(VERSION_FILE, 'w') { |fh| fh << LinodeAPI.spec_version }
29
+ end
30
+
31
+ def sha(string)
32
+ Digest::SHA256.hexdigest(string)[0..7]
33
+ end
34
+
35
+ def all_changes
36
+ {
37
+ 'version' => [
38
+ File.read(VERSION_FILE).chomp,
39
+ LinodeAPI.spec_version
40
+ ],
41
+ 'spec' => [
42
+ sha(File.read(SPEC_FILE)),
43
+ sha(YAML.dump(parse_node(LinodeAPI.spec)))
44
+ ]
45
+ }
46
+ end
47
+
48
+ Mercenary.program(:cache_spec) do |p|
49
+ p.version '0.0.1'
50
+ p.description 'Update cache file of api.apec'
51
+ p.syntax "#{$PROGRAM_NAME} [options]"
24
52
 
25
- File.open(SPEC_FILE, 'w') { |fh| fh << YAML.dump(result) }
53
+ p.option :noop, '-n', '--noop', 'No-op run (will not update the cached file'
54
+ p.option :quiet, '-q', '--quiet', 'Quiet mode'
55
+
56
+ p.action do |_, options|
57
+ puts YAML.dump(all_changes) unless options[:quiet]
58
+ write_changes unless options[:noop]
59
+ end
60
+ end
data/dev/spec.yml CHANGED
@@ -1476,117 +1476,6 @@ nodebalancer:
1476
1476
  - throws:
1477
1477
  - NOTFOUND
1478
1478
  - VALIDATION
1479
- professionalservices:
1480
- scope:
1481
- create:
1482
- - desc: Creates a new Professional Services scope submission
1483
- - params:
1484
- - application_quantity:
1485
- - desc: How many separate applications or websites are involved in this migration?
1486
- - required: false
1487
- - type: :string
1488
- - content_management:
1489
- - desc: Centralized interfaces for editing, organizing, and publishing content
1490
- - required: false
1491
- - type: :string
1492
- - crossover:
1493
- - desc: These can assist in providing reliable crossover--failures of individual
1494
- components can be transparent to the application.
1495
- - required: false
1496
- - type: :string
1497
- - current_provider:
1498
- - desc: ''
1499
- - required: false
1500
- - type: :string
1501
- - customer_name:
1502
- - desc: ''
1503
- - required: false
1504
- - type: :string
1505
- - database_server:
1506
- - desc: Generally used by applications to provide an organized way to capture
1507
- and manipulate data
1508
- - required: false
1509
- - type: :string
1510
- - email_address:
1511
- - desc: ''
1512
- - required: false
1513
- - type: :string
1514
- - linode_datacenter:
1515
- - desc: Which datacenters would you like your Linodes to be deployed in?
1516
- - required: false
1517
- - type: :string
1518
- - linode_plan:
1519
- - desc: Which Linode plans would you like to deploy?
1520
- - required: false
1521
- - type: :string
1522
- - mail_filtering:
1523
- - desc: Services here manipulate recieved messages in various ways
1524
- - required: false
1525
- - type: :string
1526
- - mail_retrieval:
1527
- - desc: User mail clients connect to these to retrieve delivered mail
1528
- - required: false
1529
- - type: :string
1530
- - mail_transfer:
1531
- - desc: Mail transfer agents facilitate message transfer between servers
1532
- - required: false
1533
- - type: :string
1534
- - managed:
1535
- - desc: ''
1536
- - required: false
1537
- - type: :string
1538
- - monitoring:
1539
- - desc: Constant monitoring of your deployed systems--these can also provide
1540
- automatic notifications for service failures.
1541
- - required: false
1542
- - type: :string
1543
- - notes:
1544
- - desc: ''
1545
- - required: false
1546
- - type: :string
1547
- - phone_number:
1548
- - desc: ''
1549
- - required: false
1550
- - type: :string
1551
- - provider_access:
1552
- - desc: What types of server access do you have at your current provider?
1553
- - required: false
1554
- - type: :string
1555
- - replication:
1556
- - desc: Redundant services often have shared state--replication automatically
1557
- propagates state changes between individual components.
1558
- - required: false
1559
- - type: :string
1560
- - requested_service:
1561
- - desc: ''
1562
- - required: false
1563
- - type: :string
1564
- - server_quantity:
1565
- - desc: How many separate servers are involved in this migration?
1566
- - required: false
1567
- - type: :string
1568
- - system_administration:
1569
- - desc: Various web interfaces for performing system administration tasks
1570
- - required: false
1571
- - type: :string
1572
- - ticket_number:
1573
- - desc: ''
1574
- - required: false
1575
- - type: :string
1576
- - web_cache:
1577
- - desc: Caching mechanisms provide temporary storage for web requests--cached
1578
- content can generally be retrieved faster.
1579
- - required: false
1580
- - type: :string
1581
- - web_server:
1582
- - desc: These provide network protocol handling for hosting websites.
1583
- - required: false
1584
- - type: :string
1585
- - webmail:
1586
- - desc: Access and administrate mail via web interfaces
1587
- - required: false
1588
- - type: :string
1589
- - throws: []
1590
1479
  stackscript:
1591
1480
  create:
1592
1481
  - desc: Create a StackScript.
@@ -1680,7 +1569,8 @@ user:
1680
1569
  getapikey:
1681
1570
  - desc: Authenticates a Linode Manager user against their username, password, and
1682
1571
  two-factor token (when enabled), and then returns a new API key, which can be
1683
- used until it expires. The number of active keys is limited to 20.
1572
+ used until it expires. The number of active keys is limited to 20. Batch requests
1573
+ will be rejected if they include this API action.
1684
1574
  - params:
1685
1575
  - expires:
1686
1576
  - desc: Number of hours the key will remain valid, between 0 and 8760. 0 means
data/dev/version ADDED
@@ -0,0 +1 @@
1
+ 3.3
data/lib/linodeapi.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'httparty'
2
3
 
3
4
  ##
@@ -6,19 +7,26 @@ module LinodeAPI
6
7
  ##
7
8
  # Default API endpoint
8
9
 
9
- DEFAULT_ENDPOINT = 'https://api.linode.com/'
10
- SPEC_URL = 'https://api.linode.com/?api_action=api.spec'
10
+ DEFAULT_ENDPOINT = 'https://api.linode.com/'.freeze
11
+ SPEC_URL = 'https://api.linode.com/?api_action=api.spec'.freeze
11
12
 
12
13
  class << self
13
14
  def spec
14
- @spec ||= { type: :group, subs: fetch_spec }
15
+ @spec ||= { type: :group, subs: parse_spec }
16
+ end
17
+
18
+ def spec_version
19
+ @spec_version ||= raw_spec['DATA']['VERSION'].to_s
15
20
  end
16
21
 
17
22
  private
18
23
 
19
- def fetch_spec
20
- raw = JSON.parse(HTTParty.get(SPEC_URL).body)['DATA']['METHODS']
21
- raw.each_with_object({}) do |(method, info), spec|
24
+ def raw_spec
25
+ @raw_spec ||= JSON.parse(HTTParty.get(SPEC_URL).body)
26
+ end
27
+
28
+ def parse_spec
29
+ raw_spec['DATA']['METHODS'].each_with_object({}) do |(method, info), spec|
22
30
  name, groups = parse_method(method)
23
31
  params = parse_params(info['PARAMETERS'])
24
32
  add_call(spec, groups, name, params, info)
data/lib/linodeapi/raw.rb CHANGED
@@ -25,14 +25,14 @@ module LinodeAPI
25
25
  def to_s
26
26
  'LinodeAPI::Raw object'
27
27
  end
28
- alias_method :inspect, :to_s
28
+ alias inspect to_s
29
29
 
30
30
  private
31
31
 
32
32
  def authenticate(params = {})
33
33
  return [] unless @names.empty?
34
34
  unless (params.values_at :username, :password).all?
35
- fail ArgumentError, 'You must provide either an API key or user/pass'
35
+ raise ArgumentError, 'You must provide either an API key or user/pass'
36
36
  end
37
37
  user.getapikey(params).api_key
38
38
  end
@@ -67,47 +67,48 @@ module LinodeAPI
67
67
  spec = @spec[:subs][method]
68
68
  method = (@names + [method.to_s]).join '.'
69
69
  options = self.class.validate method, spec[:params], params
70
- options.merge! api_key: @apikey, api_action: method
70
+ options[:api_key] = @apikey
71
+ options[:api_action] = method
71
72
  error_check self.class.post('', body: options)
72
73
  end
73
74
 
74
75
  def error_check(resp)
75
76
  code = resp.code
76
- fail("API threw HTTP error code #{code}") unless code == 200
77
+ raise("API threw HTTP error code #{code}") unless code == 200
77
78
  data = resp.parsed_response
78
- fail('Invalid API response received') if data.nil?
79
+ raise('Invalid API response received') if data.nil?
79
80
  self.class.parse data
80
81
  end
81
82
 
82
- def self.parse(resp)
83
- resp['ERRORARRAY'].reject! { |x| x['ERRORCODE'].zero? }
84
- unless resp['ERRORARRAY'].empty?
85
- fail "API Error on #{resp['ACTION']}: #{resp['ERRORARRAY']}"
83
+ class << self
84
+ def parse(resp)
85
+ resp['ERRORARRAY'].reject! { |x| x['ERRORCODE'].zero? }
86
+ unless resp['ERRORARRAY'].empty?
87
+ raise "API Error on #{resp['ACTION']}: #{resp['ERRORARRAY']}"
88
+ end
89
+ data = resp['DATA']
90
+ data.is_a?(Hash) ? clean(data) : data.map { |x| clean x }
86
91
  end
87
- data = resp['DATA']
88
- data.is_a?(Hash) ? clean(data) : data.map { |x| clean x }
89
- end
90
92
 
91
- def self.clean(object)
92
- OpenStruct.new(Hash[object.map { |k, v| [k.downcase.to_sym, v] }])
93
- end
93
+ def clean(object)
94
+ OpenStruct.new(Hash[object.map { |k, v| [k.downcase.to_sym, v] }])
95
+ end
94
96
 
95
- def self.validate(method, spec, given)
96
- spec.each_with_object({}) do |(param, info), options|
97
- if given.include? param
98
- options[param] = VALIDATION_METHODS[info[:type]].call given[param]
99
- else
100
- fail ArgumentError, "#{method} requires #{param}" if info[:required]
97
+ def validate(method, spec, given)
98
+ spec.each_with_object({}) do |(param, info), options|
99
+ if given.include? param
100
+ options[param] = VALIDATION_METHODS[info[:type]].call given[param]
101
+ elsif info[:required]
102
+ raise ArgumentError, "#{method} requires #{param}"
103
+ end
101
104
  end
102
105
  end
103
106
  end
104
107
  end
105
108
 
106
- private
107
-
108
109
  VALIDATION_METHODS = {
109
110
  boolean: proc { |e| !!e }, # rubocop:disable Style/DoubleNegation
110
111
  numeric: proc { |e| Integer(e) },
111
112
  string: proc(&:to_s)
112
- }
113
+ }.freeze
113
114
  end
data/linodeapi.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'linodeapi'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
 
6
6
  s.summary = 'Linode API wrapper'
@@ -15,11 +15,11 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_dependency 'httparty', '~> 0.13.1'
17
17
 
18
- s.add_development_dependency 'rubocop', '~> 0.34.0'
19
- s.add_development_dependency 'rake', '~> 10.4.0'
18
+ s.add_development_dependency 'rubocop', '~> 0.41.1'
19
+ s.add_development_dependency 'rake', '~> 11.2.0'
20
20
  s.add_development_dependency 'codecov', '~> 0.1.1'
21
- s.add_development_dependency 'rspec', '~> 3.3.0'
21
+ s.add_development_dependency 'rspec', '~> 3.5.0'
22
22
  s.add_development_dependency 'fuubar', '~> 2.0.0'
23
- s.add_development_dependency 'webmock', '~> 1.22.0'
24
- s.add_development_dependency 'vcr', '~> 2.9.2'
23
+ s.add_development_dependency 'webmock', '~> 2.1.0'
24
+ s.add_development_dependency 'vcr', '~> 3.0.0'
25
25
  end
@@ -42,8 +42,8 @@ describe LinodeAPI::Raw do
42
42
  end
43
43
 
44
44
  it 'accurately responds to .respond_to?' do
45
- expect(subject.respond_to? :linode).to be_truthy
46
- expect(subject.respond_to? :list).to be_falsey
45
+ expect(subject.respond_to?(:linode)).to be_truthy
46
+ expect(subject.respond_to?(:list)).to be_falsey
47
47
  end
48
48
 
49
49
  it 'returns arrays for list calls' do
@@ -13,4 +13,8 @@ describe LinodeAPI do
13
13
  expect(LinodeAPI.spec[:subs]).to be_an_instance_of Hash
14
14
  expect(LinodeAPI.spec[:subs][:linode][:subs][:create][:type]).to eql :call
15
15
  end
16
+
17
+ it 'makes the spec version available' do
18
+ expect(LinodeAPI.spec_version).to match(/[\d.]*/)
19
+ end
16
20
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,9 @@ end
9
9
 
10
10
  require 'rspec'
11
11
  require 'linodeapi'
12
+ require 'webmock'
13
+
14
+ WebMock.enable!
12
15
 
13
16
  require 'vcr'
14
17
  VCR.configure do |c|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linodeapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.34.0
33
+ version: 0.41.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.34.0
40
+ version: 0.41.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 10.4.0
47
+ version: 11.2.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 10.4.0
54
+ version: 11.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: codecov
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.3.0
75
+ version: 3.5.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.3.0
82
+ version: 3.5.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: fuubar
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.22.0
103
+ version: 2.1.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.22.0
110
+ version: 2.1.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: vcr
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 2.9.2
117
+ version: 3.0.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 2.9.2
124
+ version: 3.0.0
125
125
  description: Wraps the Linode API with multiple levels of interaction
126
126
  email: me@lesaker.org
127
127
  executables: []
@@ -129,6 +129,7 @@ extensions: []
129
129
  extra_rdoc_files: []
130
130
  files:
131
131
  - ".gitignore"
132
+ - ".prospectus"
132
133
  - ".rspec"
133
134
  - ".rubocop.yml"
134
135
  - CHANGELOG.md
@@ -139,6 +140,7 @@ files:
139
140
  - circle.yml
140
141
  - dev/cache_spec.rb
141
142
  - dev/spec.yml
143
+ - dev/version
142
144
  - lib/linodeapi.rb
143
145
  - lib/linodeapi/raw.rb
144
146
  - linodeapi.gemspec
@@ -171,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  version: '0'
172
174
  requirements: []
173
175
  rubyforge_project:
174
- rubygems_version: 2.4.5.1
176
+ rubygems_version: 2.5.1
175
177
  signing_key:
176
178
  specification_version: 4
177
179
  summary: Linode API wrapper