3scale_api 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/3scale_api.gemspec +22 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +8 -0
- data/lib/3scale_api/3scale/api.rb +86 -0
- data/lib/3scale_api/version.rb +3 -0
- data/lib/3scale_api.rb +3 -0
- data/spec/3scale_api_spec.rb +32 -0
- data/spec/spec_helper.rb +8 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0760d1fb028c4855c5477a58cc1d4f3ba1bddff3
|
4
|
+
data.tar.gz: 41562a512efbbd707b4406177eca447204d0a3cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72cdb9d77ed42d42ba8b92884386da152281c4c092354cdc1d390ffdad32ca74077634d5c4773d6bc5e4ce7179d42e1bbc57ca4cf223bac9d34d80372050013b
|
7
|
+
data.tar.gz: 6cf1433e7e57660c616c29e9771c839f0c406036e7cecb9f305c493117e201b3cc2f79943ae18263b1f4df76953202304e6f7688af797d1b5f4b73d264cb60e5
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
threescale_api
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.1
|
data/3scale_api.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require '3scale_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "3scale_api"
|
8
|
+
spec.version = Threescale::VERSION
|
9
|
+
spec.authors = ["Robbie Holmes"]
|
10
|
+
spec.email = ["robbiethegeek@gmail.com"]
|
11
|
+
spec.summary = %q{3Scale API client gem.}
|
12
|
+
spec.description = %q{This gem is to be used to interact with 3Scale's API.}
|
13
|
+
spec.homepage = "https://github.com/IDTLabs/3scale_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.test_files = Dir.glob("test/**/*.rb")
|
22
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Robbie Holmes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# 3scale - API
|
2
|
+
|
3
|
+
[](https://gitter.im/IDTLabs/threescale_api?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
[](http://badge.fury.io/rb/threescale_api)
|
5
|
+
|
6
|
+
This gem will allow developers to interact with 3Scale's APIs.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem '3scale_api'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install 3scale_api
|
24
|
+
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/[my-github-username]/threescale_api/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Threescale
|
6
|
+
class API
|
7
|
+
attr_accessor :provider_key, :url, :path, :conn
|
8
|
+
def initialize(provider_key = nil, debug = false)
|
9
|
+
if ENV['THREESCALE_URL']
|
10
|
+
@url = ENV['THREESCALE_URL']
|
11
|
+
else
|
12
|
+
raise Error, "Please set your 3 Scale URL as an environmental variable THREESCALE_URL"
|
13
|
+
end
|
14
|
+
if not provider_key
|
15
|
+
if ENV['THREESCALE_PROVIDER_KEY']
|
16
|
+
provider_key = ENV['THREESCALE_PROVIDER_KEY']
|
17
|
+
end
|
18
|
+
raise Error, "You must provide a 3 Scale provider key" if not provider_key
|
19
|
+
end
|
20
|
+
@provider_key = provider_key
|
21
|
+
@conn = Faraday.new(url = @url) do | faraday|
|
22
|
+
faraday.request :url_encoded
|
23
|
+
faraday.response :logger
|
24
|
+
faraday.adapter Faraday.default_adapter
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_application_keys(account_id, application_id)
|
29
|
+
response = @conn.get "/admin/api/accounts/#{account_id}/applications/#{application_id}/keys.xml", {
|
30
|
+
:provider_key => @provider_key, }
|
31
|
+
p response.status
|
32
|
+
return [] if response.status != 200
|
33
|
+
xml = Nokogiri::XML(response.body)
|
34
|
+
nodes = xml.xpath('keys/key')
|
35
|
+
nodes.css('value').map do |key|
|
36
|
+
key.text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
def get_application_list(account_id)
|
40
|
+
results = Array.new
|
41
|
+
response = @conn.get "/admin/api/accounts/#{account_id}/applications.xml", {:provider_key => @provider_key, }
|
42
|
+
return [] if response.status != 200
|
43
|
+
xml = Nokogiri::XML(response.body)
|
44
|
+
applications = xml.xpath('applications/application')
|
45
|
+
applications.each do |application|
|
46
|
+
keys = application.xpath("//keys/key").map do |key|
|
47
|
+
key.text
|
48
|
+
end
|
49
|
+
results.push(
|
50
|
+
{:keys => keys,
|
51
|
+
:id => application.css('id').text,
|
52
|
+
:name => application.css('name').text,
|
53
|
+
:application_id => application.css('application_id').text,
|
54
|
+
:plan_type => application.css('plan name').text})
|
55
|
+
end
|
56
|
+
results
|
57
|
+
end
|
58
|
+
def delete_application_key(account_id, application_id, key)
|
59
|
+
response = @conn.delete "/admin/api/accounts/#{account_id}/applications/#{application_id}/keys/#{key}.xml", {
|
60
|
+
:provider_key => @provider_key }
|
61
|
+
response.status == 200
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_application_key(account_id, application_id)
|
65
|
+
new_key = SecureRandom.hex(16)
|
66
|
+
response = conn.post "/admin/api/accounts/#{account_id}/applications/#{application_id}/keys.xml", {
|
67
|
+
:provider_key => @provider_key ,
|
68
|
+
:key => new_key }
|
69
|
+
response.status == 201
|
70
|
+
end
|
71
|
+
def create_application(account_id, plan_id, name, description = nil)
|
72
|
+
response = conn.post "/admin/api/accounts/#{account_id}/applications.xml", {
|
73
|
+
:provider_key => @provider_key ,
|
74
|
+
:name => name,
|
75
|
+
:description => description,
|
76
|
+
:plan_id => plan_id}
|
77
|
+
return false if response.status != 201
|
78
|
+
xml = Nokogiri::XML(response.body)
|
79
|
+
result = {
|
80
|
+
:app_id => xml.css("application application_id").text ,
|
81
|
+
:application_id => xml.css("application id").text,
|
82
|
+
:keys => [xml.css("application keys key").text]
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/3scale_api.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "3scaleApi" do
|
4
|
+
before(:all) do
|
5
|
+
ENV["THREESCALE_URL"] = nil
|
6
|
+
ENV["THREESCALE_PROVIDER_KEY"] = nil
|
7
|
+
end
|
8
|
+
it "should raise an error when there is no env variables and you instantiate" do
|
9
|
+
lambda do
|
10
|
+
Threescale::API.new
|
11
|
+
end.should raise_error
|
12
|
+
end
|
13
|
+
it "should raise an error when there is no env variables and you instantiate obj" do
|
14
|
+
lambda do
|
15
|
+
ENV["THREESCALE_URL"] = "test-url"
|
16
|
+
Threescale::API.new
|
17
|
+
end.should raise_error
|
18
|
+
end
|
19
|
+
it "should not raise an error when there is one env variables and you instantiate" do
|
20
|
+
lambda do
|
21
|
+
ENV["THREESCALE_URL"] = "test-url"
|
22
|
+
Threescale::API.new "provider-key"
|
23
|
+
end.should_not raise_error
|
24
|
+
end
|
25
|
+
it "should not raise an error when both env variables and you instantiate" do
|
26
|
+
lambda do
|
27
|
+
ENV["THREESCALE_URL"] = "test-url"
|
28
|
+
ENV["THREESCALE_PROVIDER_KEY"] = "provider-key"
|
29
|
+
Threescale::API.new
|
30
|
+
end.should_not raise_error
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: 3scale_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robbie Holmes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem is to be used to interact with 3Scale's API.
|
14
|
+
email:
|
15
|
+
- robbiethegeek@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".ruby-gemset"
|
22
|
+
- ".ruby-version"
|
23
|
+
- 3scale_api.gemspec
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/3scale_api.rb
|
29
|
+
- lib/3scale_api/3scale/api.rb
|
30
|
+
- lib/3scale_api/version.rb
|
31
|
+
- spec/3scale_api_spec.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
homepage: https://github.com/IDTLabs/3scale_api
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.4.6
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: 3Scale API client gem.
|
57
|
+
test_files: []
|