iugu-api 0.0.3 → 0.0.4
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.lock +1 -14
- data/lib/iugu-api.rb +10 -4
- data/lib/iugu-api/models/customer.rb +13 -0
- data/lib/iugu-api/models/invoice.rb +1 -1
- data/lib/iugu-api/models/invoice_log.rb +1 -1
- data/lib/iugu-api/models/iugu_resource.rb +10 -1
- data/lib/iugu-api/models/plan.rb +19 -0
- data/lib/iugu-api/models/plan_feature.rb +1 -1
- data/lib/iugu-api/models/plan_price.rb +1 -1
- data/lib/iugu-api/models/product.rb +6 -0
- data/lib/iugu-api/models/subscription.rb +27 -0
- data/lib/iugu-api/version.rb +1 -1
- metadata +5 -3
data/Gemfile.lock
CHANGED
@@ -1,24 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iugu-api (0.0.
|
5
|
-
activeresource (= 3.2.8)
|
4
|
+
iugu-api (0.0.4)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
activemodel (3.2.8)
|
11
|
-
activesupport (= 3.2.8)
|
12
|
-
builder (~> 3.0.0)
|
13
|
-
activeresource (3.2.8)
|
14
|
-
activemodel (= 3.2.8)
|
15
|
-
activesupport (= 3.2.8)
|
16
|
-
activesupport (3.2.8)
|
17
|
-
i18n (~> 0.6)
|
18
|
-
multi_json (~> 1.0)
|
19
|
-
builder (3.0.3)
|
20
|
-
i18n (0.6.1)
|
21
|
-
multi_json (1.3.6)
|
22
9
|
|
23
10
|
PLATFORMS
|
24
11
|
ruby
|
data/lib/iugu-api.rb
CHANGED
@@ -3,21 +3,25 @@ require "iugu-api/version"
|
|
3
3
|
|
4
4
|
module Iugu
|
5
5
|
module Api
|
6
|
-
@@site = "
|
6
|
+
@@site = "https://api.iugu.com"
|
7
7
|
@@token = ""
|
8
|
+
@@locale = "en"
|
8
9
|
|
9
10
|
def self.config
|
10
11
|
yield(self)
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.site
|
15
|
+
return "http://api.iugu.dev" if ENV['IUGU_PLATFORM_DEVELOPMENT']
|
14
16
|
@@site
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
def self.locale=(locale)
|
20
|
+
@@locale = locale
|
21
|
+
end
|
18
22
|
|
19
|
-
def self.
|
20
|
-
@@
|
23
|
+
def self.locale
|
24
|
+
@@locale
|
21
25
|
end
|
22
26
|
|
23
27
|
def self.token
|
@@ -40,3 +44,5 @@ require 'iugu-api/models/plan_price'
|
|
40
44
|
require 'iugu-api/models/account_payment'
|
41
45
|
require 'iugu-api/models/web_hook'
|
42
46
|
require 'iugu-api/models/subscription'
|
47
|
+
require 'iugu-api/models/product'
|
48
|
+
require 'iugu-api/models/customer'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Iugu
|
2
|
+
module Api
|
3
|
+
class Customer < IuguResource
|
4
|
+
self.format = ElasticSearchJsonFormatter.new
|
5
|
+
|
6
|
+
def invoices(options)
|
7
|
+
default_options = { limit: 10 }
|
8
|
+
params = options.merge default_options
|
9
|
+
Invoice.find :all, from: "#{Customer.prefix}invoices", params: params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Iugu
|
2
2
|
module Api
|
3
3
|
class Invoice < IuguResource
|
4
|
+
self.format = ElasticSearchJsonFormatter.new
|
4
5
|
|
5
6
|
def virtual_attributes
|
6
7
|
[ 'total_cents' ]
|
@@ -9,7 +10,6 @@ module Iugu
|
|
9
10
|
def logs(scope = :all)
|
10
11
|
Iugu::Api::InvoiceLog.find(scope, params: { invoice_id: self.id })
|
11
12
|
end
|
12
|
-
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -76,13 +76,21 @@ module ActiveResource
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
+
class ElasticSearchJsonFormatter
|
80
|
+
include ActiveResource::Formats::JsonFormat
|
81
|
+
|
82
|
+
def decode(json)
|
83
|
+
ActiveSupport::JSON.decode(json)["items"] || ActiveSupport::JSON.decode(json)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
79
87
|
module Iugu
|
80
88
|
module Api
|
81
89
|
class IuguResource < ActiveResource::Base
|
82
90
|
ActiveResource::Base.include_root_in_json = false
|
83
91
|
|
84
92
|
self.site = Iugu::Api.site
|
85
|
-
self.prefix = '/
|
93
|
+
self.prefix = '/v1/'
|
86
94
|
self.format = :json
|
87
95
|
|
88
96
|
def virtual_attributes
|
@@ -104,6 +112,7 @@ module Iugu
|
|
104
112
|
def self.find(*args)
|
105
113
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
106
114
|
options[:params] = Hash.new if options[:params].nil?
|
115
|
+
options[:params][:hl] = Iugu::Api.locale if options[:params][:hl].blank?
|
107
116
|
args.push(options)
|
108
117
|
super
|
109
118
|
end
|
data/lib/iugu-api/models/plan.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Iugu
|
2
2
|
module Api
|
3
3
|
class Plan < IuguResource
|
4
|
+
self.format = ElasticSearchJsonFormatter.new
|
5
|
+
|
4
6
|
def features(scope = :all)
|
5
7
|
Iugu::Api::PlanFeature.find(scope, :params => {:plan_id => self.id})
|
6
8
|
end
|
@@ -8,6 +10,23 @@ module Iugu
|
|
8
10
|
def prices(scope = :all)
|
9
11
|
Iugu::Api::PlanPrice.find(scope, :params => {:plan_id => self.id})
|
10
12
|
end
|
13
|
+
|
14
|
+
def price_by_currency(currency)
|
15
|
+
response = connection.get(Plan.prefix + "plans/identifier/#{self.identifier}/price/#{currency}")
|
16
|
+
if response.body == 'null'
|
17
|
+
raise ActiveResource::ResourceNotFound.new("Not Found")
|
18
|
+
else
|
19
|
+
Iugu::Api::PlanPrice.new.load(JSON.parse(response.body))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.with_currency(currency)
|
24
|
+
self.find(:all, params: { currency: currency })
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_by_identifier(identifier)
|
28
|
+
new.load(JSON.parse(connection.get( Plan.prefix + "plans/identifier/#{identifier}.json").body))
|
29
|
+
end
|
11
30
|
end
|
12
31
|
end
|
13
32
|
end
|
@@ -1,6 +1,33 @@
|
|
1
1
|
module Iugu
|
2
2
|
module Api
|
3
3
|
class Subscription < IuguResource
|
4
|
+
self.format = ElasticSearchJsonFormatter.new
|
5
|
+
|
6
|
+
def suspend
|
7
|
+
toggle_activation false
|
8
|
+
end
|
9
|
+
|
10
|
+
def activate
|
11
|
+
toggle_activation
|
12
|
+
end
|
13
|
+
|
14
|
+
def change_plan(plan_identifier)
|
15
|
+
response = connection.post(Subscription.prefix + "subscriptions/#{self.id.to_param}/change_plan/#{plan_identifier}")
|
16
|
+
raise ActiveResource::ResourceNotFound.new("Not Found") if response.body == 'null'
|
17
|
+
raise ActiveResource::ResourceInvalid if JSON.parse(response.body)["errors"]
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def toggle_activation(activate = true)
|
24
|
+
path = "activate"
|
25
|
+
path = "suspend" unless activate
|
26
|
+
response = connection.post(Subscription.prefix + "subscriptions/#{self.id.to_param}/#{path}")
|
27
|
+
raise ActiveResource::ResourceNotFound.new("Not Found") if response.body == 'null'
|
28
|
+
raise ActiveResource::ResourceInvalid if JSON.parse(response.body)["errors"]
|
29
|
+
true
|
30
|
+
end
|
4
31
|
end
|
5
32
|
end
|
6
33
|
end
|
data/lib/iugu-api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iugu-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Iugu API access
|
15
15
|
email:
|
@@ -27,12 +27,14 @@ files:
|
|
27
27
|
- iugu-api.gemspec
|
28
28
|
- lib/iugu-api.rb
|
29
29
|
- lib/iugu-api/models/account_payment.rb
|
30
|
+
- lib/iugu-api/models/customer.rb
|
30
31
|
- lib/iugu-api/models/invoice.rb
|
31
32
|
- lib/iugu-api/models/invoice_log.rb
|
32
33
|
- lib/iugu-api/models/iugu_resource.rb
|
33
34
|
- lib/iugu-api/models/plan.rb
|
34
35
|
- lib/iugu-api/models/plan_feature.rb
|
35
36
|
- lib/iugu-api/models/plan_price.rb
|
37
|
+
- lib/iugu-api/models/product.rb
|
36
38
|
- lib/iugu-api/models/subscription.rb
|
37
39
|
- lib/iugu-api/models/web_hook.rb
|
38
40
|
- lib/iugu-api/version.rb
|
@@ -58,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
60
|
version: '0'
|
59
61
|
requirements: []
|
60
62
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.10
|
62
64
|
signing_key:
|
63
65
|
specification_version: 3
|
64
66
|
summary: Iugu API access
|