amember_pro 0.0.3
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +7 -0
- data/amember_pro.gemspec +26 -0
- data/lib/amember_pro.rb +53 -0
- data/lib/amember_pro/check_access.rb +38 -0
- data/lib/amember_pro/invoices.rb +33 -0
- data/lib/amember_pro/products.rb +33 -0
- data/lib/amember_pro/users.rb +34 -0
- data/lib/amember_pro/version.rb +3 -0
- data/spec/lib/amember_pro_spec.rb +19 -0
- data/spec/spec_helper.rb +5 -0
- metadata +153 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
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,62 @@
|
|
1
|
+
# AmemberPro
|
2
|
+
|
3
|
+
A REST client for [aMember Pro Web API](http://www.amember.com/docs/REST)
|
4
|
+
This little gem should work against on aMember Pro 4.2.6
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'amember_pro'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install amember_pro
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Intialize AmemberPro:
|
23
|
+
|
24
|
+
AmemberPro(url, access_key)
|
25
|
+
|
26
|
+
Get Method:
|
27
|
+
|
28
|
+
AmemberPro::Users.get # get a list users
|
29
|
+
AmemberPro::Users.get({"_count" => 10, "_format" => "xml"}) # get 10 users and format is in xml, default format is json
|
30
|
+
AmemberPro::Users.get({"_nested[]" => "invoices"}) # pulls together with invoices
|
31
|
+
AmemberPro::Users.get({"_filter[name_f]" => "Gabino", "_filter[name_l]" => "Ang"}) # filter user with name Gabino Ang
|
32
|
+
|
33
|
+
Add Method:
|
34
|
+
|
35
|
+
AmemberPro::Users.add({:login => "mylogin", :pass => "mypass", :name_f => "Gabino", :name_l => "Ang"})
|
36
|
+
|
37
|
+
Update Method:
|
38
|
+
|
39
|
+
AmemberPro::Users.update(11, {:email => "gabino@ang.com"}) # update user's email address with id 11
|
40
|
+
|
41
|
+
Delete Method:
|
42
|
+
|
43
|
+
AmemberPro::Users.delete(13) # delete user with id 13
|
44
|
+
|
45
|
+
The above usage applies also to Invoices and Products API
|
46
|
+
|
47
|
+
## Check Access (special api)
|
48
|
+
|
49
|
+
Same as above after initialization of AmemberPro the following
|
50
|
+
methods (by-login-pass, by-login, by-email) can be called:
|
51
|
+
|
52
|
+
AmemberPro::CheckAcces.by_login_pass({:login => "mylogin", :pass => "mypass"})
|
53
|
+
|
54
|
+
Refer to this [document](http://www.amember.com/docs/REST) for all the parameters you can use
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( http://github.com/pyodor/amember_pro/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/amember_pro.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'amember_pro/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "amember_pro"
|
8
|
+
spec.version = AmemberPro::VERSION
|
9
|
+
spec.authors = ["Diosdado Campo"]
|
10
|
+
spec.email = ["csicebu@gmail.com"]
|
11
|
+
spec.summary = %q{aMember Pro Web API REST client}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
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.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
spec.add_development_dependency "webmock"
|
25
|
+
spec.add_dependency "faraday"
|
26
|
+
end
|
data/lib/amember_pro.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require "amember_pro/version"
|
3
|
+
require "amember_pro/users"
|
4
|
+
require "amember_pro/invoices"
|
5
|
+
require "amember_pro/products"
|
6
|
+
require "amember_pro/check_access"
|
7
|
+
|
8
|
+
module AmemberPro
|
9
|
+
END_POINT = 'api'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :url
|
13
|
+
attr_accessor :access_key
|
14
|
+
attr_accessor :params
|
15
|
+
attr_accessor :method
|
16
|
+
|
17
|
+
def new(url, access_key)
|
18
|
+
self.url = url
|
19
|
+
self.access_key = access_key
|
20
|
+
end
|
21
|
+
|
22
|
+
def connection(controller)
|
23
|
+
method = self.method
|
24
|
+
params = self.params
|
25
|
+
api = "/#{self::END_POINT}/#{controller.to_s}"
|
26
|
+
|
27
|
+
if method == Method::PUT or method == Method::DELETE
|
28
|
+
api += "/#{params[:id]}"
|
29
|
+
end
|
30
|
+
|
31
|
+
params[:_key] = self.access_key
|
32
|
+
conn = Faraday.new(:url => self.url, :ssl => {:verify => false})
|
33
|
+
|
34
|
+
case method
|
35
|
+
when Method::GET
|
36
|
+
conn.get api, params
|
37
|
+
when Method::POST
|
38
|
+
conn.post api, params
|
39
|
+
when Method::PUT
|
40
|
+
conn.put api, params
|
41
|
+
when Method::DELETE
|
42
|
+
conn.delete api, params
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Method
|
48
|
+
GET = 'get'
|
49
|
+
POST = 'post'
|
50
|
+
PUT = 'put'
|
51
|
+
DELETE = 'delete'
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module AmemberPro
|
2
|
+
class CheckAccess
|
3
|
+
def self.by_login_pass(params={})
|
4
|
+
check_access('by-login-pass', params)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.by_login(params={})
|
8
|
+
check_access('by-login', params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.by_email(params={})
|
12
|
+
check_access('by-email', params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.to_s
|
16
|
+
'check-access'
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.check_access(amember_method, params)
|
22
|
+
connection(Method::GET, amember_method, params).body
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.connection(method, amember_method, params={})
|
26
|
+
api = "/#{AmemberPro::END_POINT}/#{self.to_s}/#{amember_method}"
|
27
|
+
|
28
|
+
params[:_key] = AmemberPro.access_key
|
29
|
+
url = AmemberPro.url
|
30
|
+
conn = Faraday.new(:url => url, :ssl => {:verify => false})
|
31
|
+
|
32
|
+
case method
|
33
|
+
when 'get'
|
34
|
+
conn.get api, params
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AmemberPro
|
2
|
+
class Invoices
|
3
|
+
def self.get(params={})
|
4
|
+
connection(Method::GET, params).body
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.add(params)
|
8
|
+
connection(Method::POST, params).body
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.update(id, params={})
|
12
|
+
params[:id] = id
|
13
|
+
self.connection(Method::PUT, params).body
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.delete(id)
|
17
|
+
params = {:id => id}
|
18
|
+
self.connection(Method::DELETE, params).body
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.to_s
|
22
|
+
'invoices'
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.connection(method, params={})
|
28
|
+
AmemberPro.params = params
|
29
|
+
AmemberPro.method = method
|
30
|
+
AmemberPro.connection(self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AmemberPro
|
2
|
+
class Products
|
3
|
+
def self.get(params={})
|
4
|
+
connection(Method::GET, params).body
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.add(params)
|
8
|
+
connection(Method::POST, params).body
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.update(id, params={})
|
12
|
+
params[:id] = id
|
13
|
+
self.connection(Method::PUT, params).body
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.delete(id)
|
17
|
+
params = {:id => id}
|
18
|
+
self.connection(Method::DELETE, params).body
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.to_s
|
22
|
+
'products'
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.connection(method, params={})
|
28
|
+
AmemberPro.params = params
|
29
|
+
AmemberPro.method = method
|
30
|
+
AmemberPro.connection(self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module AmemberPro
|
2
|
+
class Users
|
3
|
+
|
4
|
+
def self.get(params={})
|
5
|
+
connection(Method::GET, params).body
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.add(params)
|
9
|
+
connection(Method::POST, params).body
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.update(id, params={})
|
13
|
+
params[:id] = id
|
14
|
+
self.connection(Method::PUT, params).body
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.delete(id)
|
18
|
+
params = {:id => id}
|
19
|
+
self.connection(Method::DELETE, params).body
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.to_s
|
23
|
+
'users'
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.connection(method, params={})
|
29
|
+
AmemberPro.params = params
|
30
|
+
AmemberPro.method = method
|
31
|
+
AmemberPro.connection(self)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AmemberPro do
|
4
|
+
it 'should be able to connect to an aMember domain' do
|
5
|
+
AmemberPro.new("https://billing.gcpgroup.com/", "btwKgHsxVBu5FmiAoIVU")
|
6
|
+
AmemberPro::Users.get
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should have correct initization' do
|
10
|
+
#response = AmemberPro.new('http://billing.gcpgroup.com/', 'btwKgHsxVBu5FmiAoIVU')
|
11
|
+
#response.should_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'queries user list of billing.gcpgroup.com' do
|
15
|
+
#response = AmemberPro::Users.get
|
16
|
+
|
17
|
+
#expect(response).to be_an_instance_of(String)
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amember_pro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Diosdado Campo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2014-03-26 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 5
|
33
|
+
version: "1.5"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 31
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 14
|
62
|
+
version: "2.14"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: webmock
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :development
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: faraday
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
type: :runtime
|
92
|
+
version_requirements: *id005
|
93
|
+
description: ""
|
94
|
+
email:
|
95
|
+
- csicebu@gmail.com
|
96
|
+
executables: []
|
97
|
+
|
98
|
+
extensions: []
|
99
|
+
|
100
|
+
extra_rdoc_files: []
|
101
|
+
|
102
|
+
files:
|
103
|
+
- .gitignore
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- amember_pro.gemspec
|
109
|
+
- lib/amember_pro.rb
|
110
|
+
- lib/amember_pro/check_access.rb
|
111
|
+
- lib/amember_pro/invoices.rb
|
112
|
+
- lib/amember_pro/products.rb
|
113
|
+
- lib/amember_pro/users.rb
|
114
|
+
- lib/amember_pro/version.rb
|
115
|
+
- spec/lib/amember_pro_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
has_rdoc: true
|
118
|
+
homepage: ""
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
requirements: []
|
145
|
+
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.6.2
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: aMember Pro Web API REST client
|
151
|
+
test_files:
|
152
|
+
- spec/lib/amember_pro_spec.rb
|
153
|
+
- spec/spec_helper.rb
|