3scale-api 0.1.4 → 0.1.5

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: 94f03fe320fe39054fded73ddd6fe765a1dc6057
4
- data.tar.gz: b4f7f3e2b07138c733aff57cdd419406c5d5b72b
3
+ metadata.gz: ef997b197fed97f1128b943ea537e75e185d9236
4
+ data.tar.gz: 67eb15978f939ff8ab8f120536e6785960171e62
5
5
  SHA512:
6
- metadata.gz: 2c6089e0ffb2bfdc0942506531d7cadf10287217fa2a6f344c0e7e79c914994df3db93a9d6d35cbc35235833c8e247ae5d2592f6f0ba6c404f1dcef1ffdd01aa
7
- data.tar.gz: 111169a40674449ac58bfaa837bd29ea6ef8fd58663e98c7a9a9061b4ae7ba1f4c0c3ba3c00ed40056f44d2ab392373e5e8e1b9bd00f4d5ca06bec2b9fc60b01
6
+ metadata.gz: aca3bee10f6dc8ac0a549fc5bd40fb932424143d9e6c6e9e9c54e61cb1aad91d812f4f9f4920822dbcafc713e6035298c859cd5900a82b8406ef848ed939a35e
7
+ data.tar.gz: aded44e98dfee38fd83858ba98dd4ace7b2d6f22aa878d1bfbaff3c003badfd9534efb2d63e7773c60086503527a888a3812c6cdeb3833859c5c5daa0be00e41
@@ -1,7 +1,6 @@
1
1
  module ThreeScale
2
2
  module API
3
3
  class Client
4
-
5
4
  attr_reader :http_client
6
5
 
7
6
  # @param [ThreeScale::API::HttpClient] http_client
@@ -30,7 +29,7 @@ module ThreeScale
30
29
  # @param [Fixnum] service_id Service ID
31
30
  def list_applications(service_id: nil)
32
31
  params = service_id ? { service_id: service_id } : nil
33
- response = http_client.get("/admin/api/applications", params: params)
32
+ response = http_client.get('/admin/api/applications', params: params)
34
33
  extract(collection: 'applications', entity: 'application', from: response)
35
34
  end
36
35
 
@@ -47,7 +46,7 @@ module ThreeScale
47
46
  # @param [String] user_key Application User Key
48
47
  # @param [String] application_id Application App ID
49
48
  def find_application(id: nil, user_key: nil, application_id: nil)
50
- params = { application_id: id, user_key: user_key, app_id: application_id }.reject { |_,value| value.nil? }
49
+ params = { application_id: id, user_key: user_key, app_id: application_id }.reject { |_, value| value.nil? }
51
50
  response = http_client.get('/admin/api/applications/find', params: params)
52
51
  extract(entity: 'application', from: response)
53
52
  end
@@ -61,12 +60,21 @@ module ThreeScale
61
60
  # @option attributes [String] :user_key Application User Key
62
61
  # @option attributes [String] :application_id Application App ID
63
62
  # @option attributes [String] :application_key Application App Key(s)
64
- def create_application(account_id, attributes = {}, plan_id: , **rest)
63
+ def create_application(account_id, attributes = {}, plan_id:, **rest)
65
64
  body = { plan_id: plan_id }.merge(attributes).merge(rest)
66
65
  response = http_client.post("/admin/api/accounts/#{account_id}/applications", body: body)
67
66
  extract(entity: 'application', from: response)
68
67
  end
69
68
 
69
+ # @api public
70
+ # @return [Hash] a Plan
71
+ # @param [Fixnum] account_id Account ID
72
+ # @param [Fixnum] application_id Application ID
73
+ def customize_application_plan(account_id, application_id)
74
+ response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/customize_plan")
75
+ extract(entity: 'application_plan', from: response)
76
+ end
77
+
70
78
  # @api public
71
79
  # @return [Hash] an Account
72
80
  # @param [String] name Account Name
@@ -77,7 +85,7 @@ module ThreeScale
77
85
  # @option attributes [String] :account_plan_id Account Plan ID
78
86
  # @option attributes [String] :service_plan_id Service Plan ID
79
87
  # @option attributes [String] :application_plan_id Application Plan ID
80
- def signup(attributes = {}, name: , username: , **rest)
88
+ def signup(attributes = {}, name:, username:, **rest)
81
89
  body = { org_name: name,
82
90
  username: username }.merge(attributes).merge(rest)
83
91
  response = http_client.post('/admin/api/signup', body: body)
@@ -137,7 +145,7 @@ module ThreeScale
137
145
  # @option attributes [Fixnum] :metric_id Metric ID
138
146
  def create_mapping_rule(service_id, attributes)
139
147
  response = http_client.post("/admin/api/services/#{service_id}/proxy/mapping_rules",
140
- body: { mapping_rule: attributes })
148
+ body: { mapping_rule: attributes })
141
149
  extract(entity: 'mapping_rule', from: response)
142
150
  end
143
151
 
@@ -161,7 +169,7 @@ module ThreeScale
161
169
  # @option attributes [Fixnum] :metric_id Metric ID
162
170
  def update_mapping_rule(service_id, id, attributes)
163
171
  response = http_client.patch("/admin/api/services/#{service_id}/mapping_rules/#{id}",
164
- body: { mapping_rule: attributes })
172
+ body: { mapping_rule: attributes })
165
173
  extract(entity: 'mapping_rule', from: response)
166
174
  end
167
175
 
@@ -200,7 +208,7 @@ module ThreeScale
200
208
  # @option attributes [String] :name Method Name
201
209
  def create_method(service_id, metric_id, attributes)
202
210
  response = http_client.post("/admin/api/services/#{service_id}/metrics/#{metric_id}/methods",
203
- body: { metric: attributes })
211
+ body: { metric: attributes })
204
212
  extract(entity: 'method', from: response)
205
213
  end
206
214
 
@@ -256,19 +264,16 @@ module ThreeScale
256
264
 
257
265
  protected
258
266
 
259
- def extract(collection: nil, entity: , from: )
260
- if collection
261
- from = from.fetch(collection)
262
- end
267
+ def extract(collection: nil, entity:, from:)
268
+ from = from.fetch(collection) if collection
263
269
 
264
270
  case from
265
- when Array then from.map { |e| e.fetch(entity) }
266
- when Hash then from.fetch(entity) { from }
267
- when nil then nil # raise exception?
268
- else
269
- raise "unknown #{from}"
271
+ when Array then from.map { |e| e.fetch(entity) }
272
+ when Hash then from.fetch(entity) { from }
273
+ when nil then nil # raise exception?
274
+ else
275
+ raise "unknown #{from}"
270
276
  end
271
-
272
277
  end
273
278
  end
274
279
  end
@@ -7,7 +7,7 @@ module ThreeScale
7
7
  class HttpClient
8
8
  attr_reader :endpoint, :admin_domain, :provider_key, :headers, :format
9
9
 
10
- def initialize(endpoint: , provider_key: , format: :json)
10
+ def initialize(endpoint:, provider_key:, format: :json)
11
11
  @endpoint = URI(endpoint).freeze
12
12
  @admin_domain = @endpoint.host.freeze
13
13
  @provider_key = provider_key.freeze
@@ -15,9 +15,9 @@ module ThreeScale
15
15
  @http.use_ssl = @endpoint.is_a?(URI::HTTPS)
16
16
 
17
17
  @headers = {
18
- 'Accept' => "application/#{format}",
19
- 'Content-Type' => "application/#{format}",
20
- 'Authorization' => 'Basic ' + [":#{@provider_key}"].pack('m').delete("\r\n")
18
+ 'Accept' => "application/#{format}",
19
+ 'Content-Type' => "application/#{format}",
20
+ 'Authorization' => 'Basic ' + [":#{@provider_key}"].pack('m').delete("\r\n")
21
21
  }
22
22
 
23
23
  if debug?
@@ -34,14 +34,18 @@ module ThreeScale
34
34
  parse @http.get(format_path_n_query(path, params), headers)
35
35
  end
36
36
 
37
- def patch(path, body: , params: nil)
37
+ def patch(path, body:, params: nil)
38
38
  parse @http.patch(format_path_n_query(path, params), serialize(body), headers)
39
39
  end
40
40
 
41
- def post(path, body: , params: nil)
41
+ def post(path, body:, params: nil)
42
42
  parse @http.post(format_path_n_query(path, params), serialize(body), headers)
43
43
  end
44
44
 
45
+ def put(path, body: nil, params: nil)
46
+ parse @http.put(format_path_n_query(path, params), serialize(body), headers)
47
+ end
48
+
45
49
  def delete(path, params: nil)
46
50
  parse @http.delete(format_path_n_query(path, params), headers)
47
51
  end
@@ -49,9 +53,9 @@ module ThreeScale
49
53
  # @param [::Net::HTTPResponse] response
50
54
  def parse(response)
51
55
  case response
52
- when Net::HTTPUnprocessableEntity, Net::HTTPSuccess then parser.decode(response.body)
53
- when Net::HTTPForbidden then forbidden!(response)
54
- else "Can't handle #{response.inspect}"
56
+ when Net::HTTPUnprocessableEntity, Net::HTTPSuccess then parser.decode(response.body)
57
+ when Net::HTTPForbidden then forbidden!(response)
58
+ else "Can't handle #{response.inspect}"
55
59
  end
56
60
  end
57
61
 
@@ -63,15 +67,16 @@ module ThreeScale
63
67
 
64
68
  def serialize(body)
65
69
  case body
66
- when String then body
67
- else parser.encode(body)
70
+ when nil then nil
71
+ when String then body
72
+ else parser.encode(body)
68
73
  end
69
74
  end
70
75
 
71
76
  def parser
72
77
  case format
73
- when :json then JSONParser
74
- else "unknown format #{format}"
78
+ when :json then JSONParser
79
+ else "unknown format #{format}"
75
80
  end
76
81
  end
77
82
 
@@ -93,8 +98,8 @@ module ThreeScale
93
98
 
94
99
  def decode(string)
95
100
  case string
96
- when nil, ' '.freeze, ''.freeze then nil
97
- else ::JSON.parse(string)
101
+ when nil, ' '.freeze, ''.freeze then nil
102
+ else ::JSON.parse(string)
98
103
  end
99
104
  end
100
105
 
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module API
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 3scale-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Cichra
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,8 @@ files:
80
80
  - lib/3scale/api/version.rb
81
81
  - lib/three_scale/api.rb
82
82
  homepage: https://github.com/3scale/3scale-api-ruby.
83
- licenses: []
83
+ licenses:
84
+ - MIT
84
85
  metadata: {}
85
86
  post_install_message:
86
87
  rdoc_options: []
@@ -98,9 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  requirements: []
100
101
  rubyforge_project:
101
- rubygems_version: 2.6.4
102
+ rubygems_version: 2.6.10
102
103
  signing_key:
103
104
  specification_version: 4
104
105
  summary: API Client for 3scale APIs
105
106
  test_files: []
106
- has_rdoc: