rimu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +5 -13
  2. data/.travis.yml +0 -1
  3. data/Gemfile +6 -3
  4. data/lib/rimu.rb +25 -37
  5. data/rimu.gemspec +2 -2
  6. metadata +13 -13
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDA2NzcxYWMzNzEyZmMxZmM1MzBmZWUxN2VjY2MzNzI3NmZmM2I5Nw==
5
- data.tar.gz: !binary |-
6
- ODY2MmE3N2JkNDE1YjVkZWYxNjg5ZTRkNzc3ODhmNDRlNTg0MDhmMQ==
2
+ SHA1:
3
+ metadata.gz: a41e8677143f391e930053daa0a4b716ec789150
4
+ data.tar.gz: 1c359d88df138a4423c619a7c5f84af161d6c958
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWEzNTEzMDBkZDBhYzU1YjNmYzE4ZThlMDQwOTc1ZDJjZjVjODMzZjM2MTgx
10
- NzJlMTIwMWU4OWUwZjgxZmYyYzU3NTUyZDFjMTNhMmM4ZGRiZTU1YWRjYTk4
11
- OTU2NzkzZDgwM2YxMjYzODU2YThkZjdhNDExZmRjMDhhMjg2YTc=
12
- data.tar.gz: !binary |-
13
- YTA3OWI1Yjk1NDVmMzE5NjBlZjQyNmI3NWFhNmJhYTUyYmZjY2IzNDdkZDgx
14
- Njc4NzQzNDhkNmU4M2ZhMDc2NDg5OWIyZTA0NDMxZTIwYTkxOGY0NzhjYjVi
15
- ZWY1MGUyNjE3ZTMxMGNhYTkxMjdhYWIyNjExNTA5ZDdkZjBmZmI=
6
+ metadata.gz: d2918c424fc5d58a297eb1d3282316287601b95f1ce101578c84a7ece6315233a7b4b4f17b563308010cf097497f616de5574644f22b13cc28c8cdcac37650a5
7
+ data.tar.gz: 1e0221a0bc3bdb6e50739c29a31938720f06abd9a356c929542cbec8c76c86f71a6171d6a79326e5c1ef352b5fc4671143a3eebef029170ccd30868f2001c112
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ rvm:
5
5
  - "2.1.4"
6
6
  - "2.2.1"
7
7
  script: bundle exec rspec spec
8
- before_install: gem install bundler -v 1.10.6
9
8
  addons:
10
9
  code_climate:
11
10
  repo_token: 98eb635c4bb4c62c56e531c05c69d911616f3fa319cf79a86ef7b6b783f42fa9
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test do
4
+ gem 'simplecov', :require => false
5
+ gem 'codecov', :require => false
6
+ gem 'codeclimate-test-reporter', :require => false
7
+ end
8
+
3
9
  # Specify your gem's dependencies in rimu.gemspec
4
10
  gemspec
5
- gem 'simplecov', :require => false, :group => :test
6
- gem 'codecov', :require => false, :group => :test
7
- gem 'codeclimate-test-reporter', :require => false, :group => :test
data/lib/rimu.rb CHANGED
@@ -38,35 +38,11 @@ class Rimu
38
38
  }
39
39
  end
40
40
 
41
- def post(path, data)
42
- logger.info "POST #{api_url}#{path} body:#{data.inspect}" if logger
43
- options = {headers: set_headers, body: data.to_json}
44
- HTTParty.post(api_url + path, options).parsed_response
45
- end
46
-
47
- def put(path, data)
48
- logger.info "PUT #{api_url}#{path} body:#{data.inspect}" if logger
49
- options = {headers: set_headers, body: data.to_json, read_timeout: read_timeout}
50
- HTTParty.put(api_url + path, options).parsed_response
51
- end
52
-
53
- def get(path)
54
- logger.info "GET #{api_url}#{path}" if logger
55
- options = {headers: set_headers}
56
- HTTParty.get(api_url + path, options).parsed_response
57
- end
58
-
59
- def delete(path)
60
- logger.info "DELETE #{api_url}#{path}" if logger
61
- options = {headers: set_headers}
62
- HTTParty.delete(api_url + path, options).parsed_response
63
- end
64
-
65
41
  def error?(response)
66
42
  if response.nil?
67
43
  return true
68
44
  else
69
- if response.is_a?(Hash)
45
+ if response.is_a?(Hash) && ! response.empty?
70
46
  ! response.empty? and response[response.keys[0]] and \
71
47
  response[response.keys[0]].has_key?("response_type") and \
72
48
  response[response.keys[0]]["response_type"] == "ERROR"
@@ -78,7 +54,11 @@ class Rimu
78
54
 
79
55
  def error_message(response)
80
56
  if response.nil? || ! response.is_a?(Hash) || (response.is_a?(Hash) && response.empty?)
57
+ if response.empty?
58
+ " - Error: Response was empty"
59
+ else
81
60
  " - Error: Unknown error occured"
61
+ end
82
62
  else
83
63
  if response[response.keys[0]].has_key?("human_readable_message")
84
64
  error = response[response.keys[0]]["human_readable_message"]
@@ -108,16 +88,18 @@ class Rimu
108
88
  end
109
89
 
110
90
  def send_request(path, field, method="GET", data=nil)
111
- if method == "POST"
112
- response = post(path, data)
113
- elsif method == "PUT"
114
- response = put(path, data)
115
- elsif method == "DELETE"
116
- response = delete(path)
91
+ logger.info "#{method} #{api_url}#{path} body:#{data.inspect}" if logger
92
+ if data
93
+ options = {headers: set_headers, body: data.to_json, read_timeout: read_timeout} if data
117
94
  else
118
- response = get(path)
95
+ options = {headers: set_headers}
119
96
  end
120
- raise "Errors completing request [#{path}] @ [#{api_url}] with data [#{data.inspect}]:\n#{error_message(response)}" if error?(response)
97
+ begin
98
+ response = HTTParty.send(method.downcase.to_sym, path, options).parsed_response
99
+ rescue StandardError => e
100
+ raise RimuRequestError, "Errors completing request #{method} #{api_url}#{path} with data [#{data.inspect}]:\n#{e}"
101
+ end
102
+ raise RimuResponseError, "Errors completing request #{method} #{api_url}#{path} with data [#{data.inspect}]:\n#{error_message(response)}" if error?(response)
121
103
  logger.info "Response: => #{response}" if logger
122
104
  format_response(response, field)
123
105
  end
@@ -130,10 +112,6 @@ class Rimu
130
112
  send_request("/r/billing-methods", "billing_methods")
131
113
  end
132
114
 
133
- # def pricing_plans
134
- # send_request("/r/pricing-plans", "pricing_plan_infos")
135
- # end
136
-
137
115
  def prep_data(default_params, params)
138
116
  params.keep_if {|k,_| default_params.keys.include? k }
139
117
  new_params = default_params.merge(params)
@@ -156,6 +134,7 @@ class Rimu
156
134
  :api_key => api_key,
157
135
  :api_url => api_url,
158
136
  :logger => logger,
137
+ :read_timeout => read_timeout,
159
138
  )
160
139
  instance_variable_set("@#{namespace}", subclass)
161
140
  subclass
@@ -164,5 +143,14 @@ class Rimu
164
143
  end
165
144
 
166
145
  has_namespace :orders, :servers
146
+
147
+ class RimuArgumentError < ArgumentError
148
+ end
149
+
150
+ class RimuRequestError < ArgumentError
151
+ end
152
+
153
+ class RimuResponseError < ArgumentError
154
+ end
167
155
  end
168
156
  Dir[File.expand_path(File.dirname(__FILE__) + '/rimu/*.rb')].each {|f| require f }
data/rimu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rimu"
5
- spec.version = "0.0.3"
5
+ spec.version = "0.0.4"
6
6
  spec.authors = ["Andrew Colin Kissa"]
7
7
  spec.email = ["andrew@topdog.za.net"]
8
8
  spec.license = "MPL-2.0"
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.required_ruby_version = '>= 1.9.3'
19
19
  spec.extra_rdoc_files = ['README.md']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.10"
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "rspec-core"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rimu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Colin Kissa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,42 +42,42 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '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
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-core
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-expectations
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '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
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
@@ -153,17 +153,17 @@ require_paths:
153
153
  - lib
154
154
  required_ruby_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - ! '>='
156
+ - - '>='
157
157
  - !ruby/object:Gem::Version
158
158
  version: 1.9.3
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
- - - ! '>='
161
+ - - '>='
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
165
  rubyforge_project:
166
- rubygems_version: 2.4.8
166
+ rubygems_version: 2.4.6
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: Ruby bindings for the Rimuhosting REST API