atech-billy 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/billy.rb +4 -2
- data/lib/billy/request.rb +13 -13
- data/lib/billy/service.rb +29 -0
- data/lib/billy/signup_token.rb +29 -0
- metadata +15 -3
data/lib/billy.rb
CHANGED
@@ -2,13 +2,15 @@ require 'time'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'net/https'
|
4
4
|
require 'json'
|
5
|
+
require 'basic_ssl'
|
5
6
|
|
6
7
|
require 'billy/request'
|
7
8
|
require 'billy/service'
|
9
|
+
require 'billy/signup_token'
|
8
10
|
|
9
11
|
module Billy
|
10
12
|
|
11
|
-
VERSION = '1.0.
|
13
|
+
VERSION = '1.0.1'
|
12
14
|
|
13
15
|
class << self
|
14
16
|
|
@@ -19,7 +21,7 @@ module Billy
|
|
19
21
|
attr_writer :host
|
20
22
|
|
21
23
|
def host
|
22
|
-
@host ||= 'https://
|
24
|
+
@host ||= 'https://billing.atechmedia.com'
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
data/lib/billy/request.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
module Billy
|
2
2
|
class Request
|
3
|
-
|
3
|
+
|
4
4
|
def self.request(path, data = {})
|
5
5
|
req = self.new(path, :post)
|
6
6
|
req.data = data
|
7
7
|
req.make && req.success? ? req.output : false
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
attr_reader :path, :method, :client
|
11
11
|
attr_accessor :data
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(path, method = :get)
|
14
14
|
@path = path
|
15
15
|
@method = method
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def success?
|
19
19
|
@success || false
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def output
|
23
23
|
@output || nil
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def make
|
27
27
|
uri = URI.parse([Billy.host, "api/v1", @path].join('/'))
|
28
28
|
http_request = http_class.new(uri.request_uri)
|
@@ -31,14 +31,14 @@ module Billy
|
|
31
31
|
http_request.add_field("X-Billy-Key", Billy.product_key)
|
32
32
|
|
33
33
|
http_request.set_form_data(@data)
|
34
|
-
|
34
|
+
|
35
35
|
http = Net::HTTP.new(uri.host, uri.port)
|
36
|
-
|
36
|
+
|
37
37
|
if uri.scheme == 'https'
|
38
38
|
http.use_ssl = true
|
39
39
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
http_result = http.request(http_request)
|
43
43
|
@output = JSON.parse(http_result.body)
|
44
44
|
@success = case http_result
|
@@ -47,7 +47,7 @@ module Billy
|
|
47
47
|
when Net::HTTPServiceUnavailable
|
48
48
|
raise Billy::Errors::ServiceUnavailable
|
49
49
|
when Net::HTTPForbidden, Net::HTTPUnauthorized
|
50
|
-
raise Billy::Errors::AccessDenied, "Access Denied for '#{Billy.
|
50
|
+
raise Billy::Errors::AccessDenied, "Access Denied for '#{Billy.product}'"
|
51
51
|
when Net::HTTPNotFound
|
52
52
|
json = JSON.parse(http_result.body)
|
53
53
|
raise Billy::Errors::NotFound, json['error']
|
@@ -59,9 +59,9 @@ module Billy
|
|
59
59
|
end
|
60
60
|
self
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
private
|
64
|
-
|
64
|
+
|
65
65
|
def http_class
|
66
66
|
case @method
|
67
67
|
when :post then Net::HTTP::Post
|
@@ -71,6 +71,6 @@ module Billy
|
|
71
71
|
Net::HTTP::Get
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
76
|
end
|
data/lib/billy/service.rb
CHANGED
@@ -14,6 +14,35 @@ module Billy
|
|
14
14
|
session ? [Billy.host, 'start', session['token']].join('/') : false
|
15
15
|
end
|
16
16
|
|
17
|
+
## Create a new signup token for another application
|
18
|
+
def create_signup_token(product, package)
|
19
|
+
return false if product.nil? || package.nil?
|
20
|
+
token = Billy::Request.request('services/create_signup_token', :id => @attributes['id'], :product => product, :package => package)
|
21
|
+
token ? token['url'] : false
|
22
|
+
end
|
23
|
+
|
24
|
+
## Change the user associated with this service to the given aTech identity key
|
25
|
+
def change_user(atech_identity_key)
|
26
|
+
request = Billy::Request.request('services/change_user', :id => @attributes['id'], :atech_identity_key => atech_identity_key)
|
27
|
+
if request
|
28
|
+
@attributes = request
|
29
|
+
return true
|
30
|
+
else
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
## Change the label associated with a service
|
36
|
+
def change_label(new_label)
|
37
|
+
request = Billy::Request.request('services/change_label', :id => @attributes['id'], :label => new_label)
|
38
|
+
if request
|
39
|
+
@attributes = request
|
40
|
+
return true
|
41
|
+
else
|
42
|
+
return false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
17
46
|
def method_missing(param)
|
18
47
|
@attributes[param.to_s] || super
|
19
48
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Billy
|
2
|
+
class SignupToken
|
3
|
+
|
4
|
+
attr_reader :attributes
|
5
|
+
|
6
|
+
def initialize(attributes)
|
7
|
+
@attributes = attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
def service?
|
11
|
+
self.attributes.include?(:service)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create(partner)
|
15
|
+
attributes = Billy::Request.request('signup_tokens/create', :partner => partner)
|
16
|
+
attributes.is_a?(Hash) ? self.new(attributes) : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find(token)
|
20
|
+
attributes = Billy::Request.request('signup_tokens/info', :token => token)
|
21
|
+
attributes.is_a?(Hash) ? self.new(attributes) : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(param)
|
25
|
+
@attributes[param.to_s] || super
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atech-billy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-05-31 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: basic_ssl
|
16
|
+
requirement: &70223088107580 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70223088107580
|
14
25
|
description:
|
15
26
|
email: adam@atechmedia.com
|
16
27
|
executables: []
|
@@ -20,6 +31,7 @@ files:
|
|
20
31
|
- lib/billy.rb
|
21
32
|
- lib/billy/request.rb
|
22
33
|
- lib/billy/service.rb
|
34
|
+
- lib/billy/signup_token.rb
|
23
35
|
homepage: http://atechmedia.com
|
24
36
|
licenses: []
|
25
37
|
post_install_message:
|