iugu-api 0.0.1b

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 ADDED
@@ -0,0 +1,23 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/
5
+ .sass-cache/
6
+ coverage/
7
+ *~
8
+ *.DS_Store
9
+ *.out
10
+ *.swp
11
+ .sass-cache/
12
+ .sass-cache/*
13
+ .sass-cache/**
14
+ tmp/
15
+ tmp/*/*
16
+ tmp/**
17
+ */*.swp
18
+ db/schema.rb
19
+ public/system/*
20
+ public/system/**
21
+ coverage/**
22
+ coverage/*/*
23
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iugu-api.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ iugu-api (0.0.1)
5
+ activeresource (= 3.2.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ 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
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ iugu-api!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexandre Paez
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,29 @@
1
+ # Iugu::Api
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'iugu-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install iugu-api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/iugu-api.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iugu-api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "iugu-api"
8
+ gem.version = Iugu::Api::VERSION
9
+ gem.authors = ["Alexandre Paez"]
10
+ gem.email = ["alepaezseq@gmail.com"]
11
+ gem.description = "Iugu API access"
12
+ gem.summary = "Iugu API access"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ #gem.add_dependency "activeresource", "3.2.8"
21
+ end
data/lib/iugu-api.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "active_resource"
2
+ require "iugu-api/version"
3
+
4
+ module Iugu
5
+ module Api
6
+ @@site = "http://iugu.dev:3000"
7
+ @@token = ""
8
+
9
+ def self.config
10
+ yield(self)
11
+ end
12
+
13
+ def self.site
14
+ @@site
15
+ end
16
+
17
+ # TODO: Tirar o setter de site
18
+
19
+ def self.site=(site)
20
+ @@site = site
21
+ end
22
+
23
+ def self.token
24
+ @@token
25
+ end
26
+
27
+ def self.token=(token)
28
+ @@token = token
29
+ Iugu::Api::IuguResource.user = token
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'iugu-api/models/iugu_resource.rb'
35
+ require 'iugu-api/models/invoice'
36
+ require 'iugu-api/models/invoice_log'
37
+ require 'iugu-api/models/plan'
38
+ require 'iugu-api/models/plan_feature'
39
+ require 'iugu-api/models/plan_price'
40
+ require 'iugu-api/models/account_payment'
41
+ require 'iugu-api/models/web_hook'
42
+ require 'iugu-api/models/subscription'
@@ -0,0 +1,7 @@
1
+ module Iugu
2
+ module Api
3
+ class AccountPayment < IuguResource
4
+ self.element_name = "payment_method"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Iugu
2
+ module Api
3
+ class Invoice < IuguResource
4
+
5
+ def virtual_attributes
6
+ [ 'total_cents' ]
7
+ end
8
+
9
+ def logs(scope = :all)
10
+ Iugu::Api::InvoiceLog.find(scope, params: { invoice_id: self.id })
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ module Iugu
2
+ module Api
3
+ class InvoiceLog < IuguResource
4
+ self.prefix = '/api/v1/invoices/:invoice_id/'
5
+ self.element_name = 'log'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,113 @@
1
+ require 'active_resource/validations'
2
+
3
+ module ActiveResource
4
+ class ResourceInvalid < ClientError #:nodoc:
5
+ end
6
+
7
+ # Active Resource validation is reported to and from this object, which is used by Base#save
8
+ # to determine whether the object in a valid state to be saved. See usage example in Validations.
9
+ class Errors < ActiveModel::Errors
10
+ # Grabs errors from an array of messages (like ActiveRecord::Validations).
11
+ # The second parameter directs the errors cache to be cleared (default)
12
+ # or not (by passing true).
13
+ def from_array(messages, save_cache = false)
14
+ clear unless save_cache
15
+ humanized_attributes = Hash[@base.attributes.keys.map { |attr_name| [attr_name.humanize, attr_name] }]
16
+ messages.each do |message|
17
+ attr_message = humanized_attributes.keys.detect do |attr_name|
18
+ if message[0, attr_name.size + 1] == "#{attr_name} "
19
+ add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
20
+ end
21
+ end
22
+
23
+ self[:base] << message if attr_message.nil?
24
+ end
25
+ end
26
+
27
+ # Grabs errors from a hash of attribute => array of errors elements
28
+ # The second parameter directs the errors cache to be cleared (default)
29
+ # or not (by passing true)
30
+ #
31
+ # Unrecognized attribute names will be humanized and added to the record's
32
+ # base errors.
33
+ def from_hash(messages, save_cache = false)
34
+ clear unless save_cache
35
+
36
+ messages.each do |(key,errors)|
37
+ errors.each do |error|
38
+ if @base.attributes.keys.include?(key)
39
+ add key, error
40
+ elsif key == 'base'
41
+ self[:base] << error
42
+ else
43
+ # reporting an error on an attribute not in attributes
44
+ # format and add them to base
45
+ self[:base] << "#{key.humanize} #{error}"
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # Grabs errors from a json response.
52
+ def from_json(json, save_cache = false)
53
+ decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
54
+ if decoded.kind_of?(Hash) && (decoded.has_key?('errors') || decoded.empty?)
55
+ errors = decoded['errors'] || {}
56
+ if errors.kind_of?(Array)
57
+ # 3.2.1-style with array of strings
58
+ ActiveSupport::Deprecation.warn('Returning errors as an array of strings is deprecated.')
59
+ from_array errors, save_cache
60
+ else
61
+ # 3.2.2+ style
62
+ from_hash errors, save_cache
63
+ end
64
+ else
65
+ # <3.2-style respond_with - lacks 'errors' key
66
+ ActiveSupport::Deprecation.warn('Returning errors as a hash without a root "errors" key is deprecated.')
67
+ from_hash decoded, save_cache
68
+ end
69
+ end
70
+
71
+ # Grabs errors from an XML response.
72
+ def from_xml(xml, save_cache = false)
73
+ array = Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue []
74
+ from_array array, save_cache
75
+ end
76
+ end
77
+ end
78
+
79
+ module Iugu
80
+ module Api
81
+ class IuguResource < ActiveResource::Base
82
+ ActiveResource::Base.include_root_in_json = false
83
+
84
+ self.site = Iugu::Api.site
85
+ self.prefix = '/api/v1/'
86
+ self.format = :json
87
+
88
+ def virtual_attributes
89
+ []
90
+ end
91
+
92
+ def build_options( options={} )
93
+ options.merge( { :except => virtual_attributes } )
94
+ end
95
+
96
+ def to_json(options={})
97
+ super(build_options(include_root_in_json ? { :root => self.class.element_name }.merge(options) : { root: nil }.merge(options)))
98
+ end
99
+
100
+ def to_xml(options={})
101
+ super( build_options({ :root => self.class.element_name }.merge(options)) )
102
+ end
103
+
104
+ def self.find(*args)
105
+ options = args.last.is_a?(Hash) ? args.pop : {}
106
+ options[:params] = Hash.new if options[:params].nil?
107
+ args.push(options)
108
+ super
109
+ end
110
+
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,13 @@
1
+ module Iugu
2
+ module Api
3
+ class Plan < IuguResource
4
+ def features(scope = :all)
5
+ Iugu::Api::PlanFeature.find(scope, :params => {:plan_id => self.id})
6
+ end
7
+
8
+ def prices(scope = :all)
9
+ Iugu::Api::PlanPrice.find(scope, :params => {:plan_id => self.id})
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module Iugu
2
+ module Api
3
+ class PlanFeature < IuguResource
4
+ self.prefix = "/api/v1/plans/:plan_id/"
5
+ self.element_name = "feature"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Iugu
2
+ module Api
3
+ class PlanPrice < IuguResource
4
+ self.prefix = "/api/v1/plans/:plan_id/"
5
+ self.element_name = "price"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Iugu
2
+ module Api
3
+ class Subscription < IuguResource
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Iugu
2
+ module Api
3
+ class WebHook < IuguResource
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Iugu
2
+ module Api
3
+ VERSION = "0.0.1b"
4
+ end
5
+ end
Binary file
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iugu-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1b
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Alexandre Paez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Iugu API access
15
+ email:
16
+ - alepaezseq@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - iugu-api.gemspec
28
+ - lib/iugu-api.rb
29
+ - lib/iugu-api/models/account_payment.rb
30
+ - lib/iugu-api/models/invoice.rb
31
+ - lib/iugu-api/models/invoice_log.rb
32
+ - lib/iugu-api/models/iugu_resource.rb
33
+ - lib/iugu-api/models/plan.rb
34
+ - lib/iugu-api/models/plan_feature.rb
35
+ - lib/iugu-api/models/plan_price.rb
36
+ - lib/iugu-api/models/subscription.rb
37
+ - lib/iugu-api/models/web_hook.rb
38
+ - lib/iugu-api/version.rb
39
+ - pkg/iugu-api-0.0.1.gem
40
+ homepage: ''
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>'
56
+ - !ruby/object:Gem::Version
57
+ version: 1.3.1
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Iugu API access
64
+ test_files: []