apigee-platform 0.0.2
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.
- data/Gemfile +15 -0
- data/Gemfile.lock +96 -0
- data/LICENSE.txt +20 -0
- data/README.md +173 -0
- data/Rakefile +44 -0
- data/lib/apigee-platform.rb +5 -0
- data/lib/apigee-platform/associations.rb +70 -0
- data/lib/apigee-platform/custom_attributes.rb +34 -0
- data/lib/apigee-platform/objects/api.rb +11 -0
- data/lib/apigee-platform/objects/apiproduct.rb +10 -0
- data/lib/apigee-platform/objects/app.rb +11 -0
- data/lib/apigee-platform/objects/base.rb +88 -0
- data/lib/apigee-platform/objects/company.rb +13 -0
- data/lib/apigee-platform/objects/company_app.rb +17 -0
- data/lib/apigee-platform/objects/company_app_key.rb +7 -0
- data/lib/apigee-platform/objects/developer.rb +20 -0
- data/lib/apigee-platform/objects/developer_app.rb +17 -0
- data/lib/apigee-platform/objects/developer_app_key.rb +7 -0
- data/lib/apigee-platform/objects/key.rb +49 -0
- data/lib/apigee-platform/version.rb +10 -0
- data/spec/associations_spec.rb +130 -0
- data/spec/custom_attributes_spec.rb +34 -0
- data/spec/objects/developer_app_key_spec.rb +112 -0
- data/spec/objects/developer_spec.rb +72 -0
- data/spec/spec_helper.rb +17 -0
- metadata +234 -0
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "activeresource", "~> 3.2.12"
|
4
|
+
gem 'json', '~> 1.7.7'
|
5
|
+
gem 'oj', '>= 2.0.0'
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "shoulda", ">= 0"
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", ">= 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.8.4"
|
12
|
+
gem "simplecov", ">= 0"
|
13
|
+
gem "rspec", "~> 2.8.0"
|
14
|
+
gem "webmock", "1.8.0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.13)
|
5
|
+
activesupport (= 3.2.13)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activeresource (3.2.13)
|
8
|
+
activemodel (= 3.2.13)
|
9
|
+
activesupport (= 3.2.13)
|
10
|
+
activesupport (3.2.13)
|
11
|
+
i18n (= 0.6.1)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
addressable (2.3.5)
|
14
|
+
builder (3.0.4)
|
15
|
+
crack (0.4.0)
|
16
|
+
safe_yaml (~> 0.9.0)
|
17
|
+
diff-lcs (1.1.3)
|
18
|
+
faraday (0.8.7)
|
19
|
+
multipart-post (~> 1.1)
|
20
|
+
git (1.2.5)
|
21
|
+
github_api (0.10.1)
|
22
|
+
addressable
|
23
|
+
faraday (~> 0.8.1)
|
24
|
+
hashie (>= 1.2)
|
25
|
+
multi_json (~> 1.4)
|
26
|
+
nokogiri (~> 1.5.2)
|
27
|
+
oauth2
|
28
|
+
hashie (2.0.5)
|
29
|
+
highline (1.6.19)
|
30
|
+
httpauth (0.2.0)
|
31
|
+
i18n (0.6.1)
|
32
|
+
jeweler (1.8.6)
|
33
|
+
builder
|
34
|
+
bundler (~> 1.0)
|
35
|
+
git (>= 1.2.5)
|
36
|
+
github_api (= 0.10.1)
|
37
|
+
highline (>= 1.6.15)
|
38
|
+
nokogiri (= 1.5.10)
|
39
|
+
rake
|
40
|
+
rdoc
|
41
|
+
json (1.7.7)
|
42
|
+
jwt (0.1.8)
|
43
|
+
multi_json (>= 1.5)
|
44
|
+
multi_json (1.7.7)
|
45
|
+
multi_xml (0.5.4)
|
46
|
+
multipart-post (1.2.0)
|
47
|
+
nokogiri (1.5.10)
|
48
|
+
oauth2 (0.9.2)
|
49
|
+
faraday (~> 0.8)
|
50
|
+
httpauth (~> 0.2)
|
51
|
+
jwt (~> 0.1.4)
|
52
|
+
multi_json (~> 1.0)
|
53
|
+
multi_xml (~> 0.5)
|
54
|
+
rack (~> 1.2)
|
55
|
+
oj (2.1.3)
|
56
|
+
rack (1.5.2)
|
57
|
+
rake (10.1.0)
|
58
|
+
rdoc (3.12.2)
|
59
|
+
json (~> 1.4)
|
60
|
+
rspec (2.8.0)
|
61
|
+
rspec-core (~> 2.8.0)
|
62
|
+
rspec-expectations (~> 2.8.0)
|
63
|
+
rspec-mocks (~> 2.8.0)
|
64
|
+
rspec-core (2.8.0)
|
65
|
+
rspec-expectations (2.8.0)
|
66
|
+
diff-lcs (~> 1.1.2)
|
67
|
+
rspec-mocks (2.8.0)
|
68
|
+
safe_yaml (0.9.3)
|
69
|
+
shoulda (3.5.0)
|
70
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
71
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
72
|
+
shoulda-context (1.1.4)
|
73
|
+
shoulda-matchers (2.2.0)
|
74
|
+
activesupport (>= 3.0.0)
|
75
|
+
simplecov (0.7.1)
|
76
|
+
multi_json (~> 1.0)
|
77
|
+
simplecov-html (~> 0.7.1)
|
78
|
+
simplecov-html (0.7.1)
|
79
|
+
webmock (1.8.0)
|
80
|
+
addressable (>= 2.2.7)
|
81
|
+
crack (>= 0.1.7)
|
82
|
+
|
83
|
+
PLATFORMS
|
84
|
+
ruby
|
85
|
+
|
86
|
+
DEPENDENCIES
|
87
|
+
activeresource (~> 3.2.12)
|
88
|
+
bundler (>= 1.0.0)
|
89
|
+
jeweler (~> 1.8.4)
|
90
|
+
json (~> 1.7.7)
|
91
|
+
oj (>= 2.0.0)
|
92
|
+
rdoc (~> 3.12)
|
93
|
+
rspec (~> 2.8.0)
|
94
|
+
shoulda
|
95
|
+
simplecov
|
96
|
+
webmock (= 1.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Vasiliy Sablin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
# ApigeePlatform
|
2
|
+
|
3
|
+
ApigeePlatform is a ruby wrapper for Apigee Platform API (http://apigee.com/).
|
4
|
+
|
5
|
+
Full API documentation - http://apigee.com/docs/api/api-resources
|
6
|
+
|
7
|
+
Gem is based on ActiveResource.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
gem install apigee-platform
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Initialization
|
15
|
+
require 'apigee-platform'
|
16
|
+
|
17
|
+
ApigeePlatform::Objects::Base.configure :user => 'user@example.com', :password => 'your_password', :organization => 'your_apigee_org'
|
18
|
+
|
19
|
+
### Examples
|
20
|
+
|
21
|
+
#### Developer
|
22
|
+
|
23
|
+
Retreive developers list
|
24
|
+
|
25
|
+
ApigeePlatform::Objects::Developer.all
|
26
|
+
# => ["liukang@example.com", "kano@example.com"]
|
27
|
+
|
28
|
+
Find developer. You could use email or ID here.
|
29
|
+
|
30
|
+
developer = ApigeePlatform::Objects::Developer.find 'johnny@example.com'
|
31
|
+
|
32
|
+
Create new developer
|
33
|
+
|
34
|
+
developer = ApigeePlatform::Objects::Developer.new :firstName => 'Johnny', :lastName => 'Cage', :userName => 'johnnycage', :email => 'johnny@example.com'
|
35
|
+
developer.save
|
36
|
+
# => true
|
37
|
+
|
38
|
+
developer.errors.full_messages
|
39
|
+
# => []
|
40
|
+
|
41
|
+
Update developer attributes
|
42
|
+
|
43
|
+
developer.firstName = 'SuperJohnny'
|
44
|
+
developer.save
|
45
|
+
# => true
|
46
|
+
|
47
|
+
Get Apps assigned to developer
|
48
|
+
|
49
|
+
developer.apps
|
50
|
+
# => ['app1', 'app2']
|
51
|
+
|
52
|
+
Create new app for developer
|
53
|
+
|
54
|
+
new_app = developer.create_app
|
55
|
+
new_app.name = 'my_super_app'
|
56
|
+
new_app.save
|
57
|
+
# => true
|
58
|
+
|
59
|
+
Find developer app by name
|
60
|
+
|
61
|
+
app = developer.app 'my_super_app'
|
62
|
+
|
63
|
+
# or you could use DeveloperApp resource directly
|
64
|
+
app = ApigeePlatform::Objects::DeveloperApp.find 'my_super_app', :params => {:developer_id => DEVELOPER_ID_OR_EMAIL}
|
65
|
+
|
66
|
+
Get developer app keys. Keys were created automatically by Apigee with app.
|
67
|
+
|
68
|
+
app.keys
|
69
|
+
|
70
|
+
Manage apiproducts of key
|
71
|
+
|
72
|
+
key = app.keys.first
|
73
|
+
|
74
|
+
# assigned apiproducts for key
|
75
|
+
key.apiproducts
|
76
|
+
# => {}
|
77
|
+
|
78
|
+
# existing apiproducts list
|
79
|
+
ApigeePlatform::Objects::Apiproduct.all
|
80
|
+
# => ['mkworld', 'midway']
|
81
|
+
|
82
|
+
key.add_product 'mytest'
|
83
|
+
# => 'pending'
|
84
|
+
|
85
|
+
key.apiproducts
|
86
|
+
# => {"mytest"=>"pending"}
|
87
|
+
|
88
|
+
# approve product
|
89
|
+
key.approve_product 'mytest'
|
90
|
+
# => "approved"
|
91
|
+
|
92
|
+
# revoke product
|
93
|
+
key.revoke_product 'mytest'
|
94
|
+
# => "revoked"
|
95
|
+
|
96
|
+
# remove product
|
97
|
+
key.remove_product 'mytest'
|
98
|
+
# => true
|
99
|
+
|
100
|
+
Delete developer app
|
101
|
+
|
102
|
+
app.destroy
|
103
|
+
|
104
|
+
Delete developer
|
105
|
+
|
106
|
+
developer.destroy
|
107
|
+
|
108
|
+
|
109
|
+
#### Company
|
110
|
+
|
111
|
+
Comapnies API is similar to developers API.
|
112
|
+
|
113
|
+
company = ApigeePlatform::Objects::Company.create :name => 'my_new_company'
|
114
|
+
|
115
|
+
company.apps
|
116
|
+
# => []
|
117
|
+
|
118
|
+
new_app = company.create_app
|
119
|
+
new_app.name = 'my_super_app2'
|
120
|
+
new_app.save
|
121
|
+
# => true
|
122
|
+
|
123
|
+
key = new_app.keys.first
|
124
|
+
|
125
|
+
key.add_product 'mytest'
|
126
|
+
# => 'pending'
|
127
|
+
|
128
|
+
key.apiproducts
|
129
|
+
# => {"mytest"=>"pending"}
|
130
|
+
|
131
|
+
# approve product
|
132
|
+
key.approve_product 'mytest'
|
133
|
+
# => "approved"
|
134
|
+
|
135
|
+
# revoke product
|
136
|
+
key.revoke_product 'mytest'
|
137
|
+
# => "revoked"
|
138
|
+
|
139
|
+
# remove product
|
140
|
+
key.remove_product 'mytest'
|
141
|
+
# => true
|
142
|
+
|
143
|
+
#### Custom attributes
|
144
|
+
|
145
|
+
Some resources (developer, company, apiproduct) has custom attributes. It is accessible under custom_attributes method which behave like a Hash.
|
146
|
+
|
147
|
+
developer.custom_attributes
|
148
|
+
# => {}
|
149
|
+
|
150
|
+
developer.custom_attributes[:attr1] = 'val1'
|
151
|
+
developer.save
|
152
|
+
|
153
|
+
## Contributing to apigee-platform
|
154
|
+
|
155
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
156
|
+
* Fork the project.
|
157
|
+
* Start a feature/bugfix branch.
|
158
|
+
* Commit and push until you are happy with your contribution.
|
159
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
160
|
+
|
161
|
+
## Copyright
|
162
|
+
|
163
|
+
Copyright (c) 2013 Vasiliy Sablin. See LICENSE.txt for
|
164
|
+
further details.
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH << "./lib/"
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
require 'rake'
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
require 'apigee-platform'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
gem.name = "apigee-platform"
|
19
|
+
gem.homepage = "http://github.com/woodoo/apigee-platform"
|
20
|
+
gem.summary = %Q{This is a ruby wrapper for Apigee Platform API (http://apigee.com/)}
|
21
|
+
gem.description = gem.summary
|
22
|
+
gem.email = "vasiliy.sablin@gmail.com"
|
23
|
+
gem.authors = ["Vasiliy Sablin"]
|
24
|
+
gem.version = ApigeePlatform::Version::STRING
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = ApigeePlatform::Version::STRING
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "apigee-platform #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module ApigeePlatform
|
2
|
+
module Associations
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def has_many(*args)
|
11
|
+
klass_sym = args.first.to_sym
|
12
|
+
options = args.extract_options!
|
13
|
+
prefix = self.name
|
14
|
+
klass_name = prefix + klass_sym.to_s.classify
|
15
|
+
|
16
|
+
instance_eval do
|
17
|
+
define_method "#{klass_sym}" do |scope = :all|
|
18
|
+
klass = klass_name.constantize
|
19
|
+
prefix_params = klass.prefix_options.inject({}) do |res,pair|
|
20
|
+
res[pair.first] = self.send(options[pair.first] || pair.last)
|
21
|
+
res
|
22
|
+
end
|
23
|
+
|
24
|
+
if options[:through].present?
|
25
|
+
self.send(options[:through]).map do |el|
|
26
|
+
klass.instantiate_record(el.attributes, prefix_params)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
klass.find scope, :params => prefix_params
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
define_method "#{klass_sym.to_s.singularize}" do |id = nil|
|
34
|
+
if id
|
35
|
+
method(klass_sym).call(id)
|
36
|
+
else
|
37
|
+
method("create_#{klass_sym.to_s.singularize}").call
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
define_method "create_#{klass_sym.to_s.singularize}" do |params={}|
|
42
|
+
klass = klass_name.constantize
|
43
|
+
prefix_params = klass.prefix_options.inject({}){|res,pair| res[pair.last] = self.send(options[pair.first] || pair.last); res }
|
44
|
+
klass.new params.merge(prefix_params)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def belongs_to(*args)
|
52
|
+
klass_sym = args.first.to_sym
|
53
|
+
options = args.extract_options!
|
54
|
+
prefix = "#{self.parent}::"
|
55
|
+
klass_name = prefix + klass_sym.to_s.classify
|
56
|
+
klass_name = prefix + options[:class_name] if options[:class_name]
|
57
|
+
|
58
|
+
instance_eval do
|
59
|
+
define_method "#{klass_sym}" do
|
60
|
+
klass = klass_name.constantize
|
61
|
+
id_key = options[:key] ? options[:key] : klass.primary_key
|
62
|
+
klass.find self.send(id_key)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ApigeePlatform
|
2
|
+
class CustomAttributes
|
3
|
+
|
4
|
+
def initialize(obj)
|
5
|
+
@object = obj
|
6
|
+
@object.attributes['attributes'] ||= []
|
7
|
+
@attributes = @object.attributes['attributes'].inject({}.with_indifferent_access){|res, a| res[a['name']] = a['value']; res}
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
@attributes[key.to_s]
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(key, value)
|
15
|
+
delete(key.to_s)
|
16
|
+
@object.attributes['attributes'] << {'name' => key.to_s, 'value' => value}
|
17
|
+
@attributes[key.to_s] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(key)
|
21
|
+
@object.attributes['attributes'].reject!{|a| a['name'] == key.to_s}
|
22
|
+
@attributes.delete(key.to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(name)
|
26
|
+
@attributes.send(name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def inspect
|
30
|
+
@attributes.inspect
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|