contaazul 0.1.0dev

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWM5YWE0NjhhYWM1OThkMTM5OTM2MzNiYjQ2NzA2NzlhZWZhZDMxYw==
5
+ data.tar.gz: !binary |-
6
+ NDFmODRiODhjNWI0MzMwMjNmYmNmMGE3MWRkNWE4ZWU5YjhjMTQ5Yg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTEwMzJlM2E2Y2VkY2ZlMmEzOTdmM2U3MWE4YmM5ZDYwNDBmOTdkMmQ5OGU1
10
+ MmVjZDlhM2I1MWFiNzI0NTYxNGY4N2M2MWY2MGRhM2FlY2ZhMjI5MDU2OTgx
11
+ MGIyM2U2MzM5NWY2ZDcyZjAyNTBjMzUyMDA3YjAwYzUxZDhkMGM=
12
+ data.tar.gz: !binary |-
13
+ NDQzM2JkYjgyZmRkYTZhMTZmMTMzZTg5MWM2YjFlZWY3MWZhYzM4OGZiNTJi
14
+ YjAwYWNiY2M3NWE5YTBkYTBlZGIwZDE1NThiOGQ2ODBiZDYyZDEwYTFlZWZh
15
+ ZDYwYWE1YjJlMzc0NDA4ODhmNjk1OGEzOGRmNTJkNGRmZDMxMzM=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - jruby-18mode # JRuby in 1.8 mode
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - 1.8.7
7
+ - 1.9.2
8
+ - 1.9.3
9
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec', '>= 2.11'
11
+ gem 'guard-rspec'
12
+
13
+ gem 'json', '~> 1.7', :platforms => [:ruby_18, :jruby]
14
+ gem 'webmock'
15
+ end
16
+
17
+ gemspec
@@ -0,0 +1,5 @@
1
+ DO WHATEVER YOU WANT TO!
2
+
3
+
4
+ This project is basically a fork of [octokit.rb](https://github.com/octokit/octokit.rb)
5
+ See octokit.rb's license for more info.
@@ -0,0 +1,48 @@
1
+ # contaazul
2
+ [![Dependency Status](https://gemnasium.com/jnettome/contaazul.png)](https://gemnasium.com/jnettome/contaazul) [![Build Status](https://travis-ci.org/jnettome/contaazul.png?branch=master)](https://travis-ci.org/jnettome/contaazul)
3
+
4
+ A tiny *non-official* wrapper for [ContaAzul](http://contaazul.com.br)'s API.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'contaazul'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install contaazul
19
+
20
+ ## Usage
21
+
22
+ ### Get all customers
23
+ Contaazul.customers
24
+
25
+
26
+ ## JSON dependency
27
+
28
+ Since JSON is included in 1.9 now, we no longer include it as a hard
29
+ dependency. Please require it explicitly if you're running Ruby 1.8
30
+
31
+ gem 'json', '~> 1.7'
32
+
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
41
+
42
+ ## Copyright
43
+
44
+ DO WHATEVER YOU WANT TO!
45
+ This project is basically a fork of [octokit.rb](https://github.com/octokit/octokit.rb)
46
+ See [LICENSE][] for details.
47
+
48
+ [license]: LICENSE.md
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :test => :spec
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'contaazul/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "contaazul"
8
+ spec.version = Contaazul::VERSION
9
+ spec.authors = ["Jo\xC3\xA3o Netto"]
10
+ spec.email = ["hi@joaonetto.me"]
11
+ spec.description = %q{A tiny non-official wrapper for ContaAzul's API}
12
+ spec.summary = %q{Integrate your ruby app with ContaAzul's API (contaazul.com.br)}
13
+ spec.homepage = "https://github.com/jnettome/contaazul"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'addressable', '~> 2.3.4'
25
+ spec.add_dependency 'faraday', '~> 0.8.7'
26
+ spec.add_dependency 'multi_json', '~> 1.7.6'
27
+
28
+ spec.required_rubygems_version = '>= 1.8'
29
+ end
@@ -0,0 +1,25 @@
1
+ require "contaazul/configuration"
2
+ require "contaazul/version"
3
+ require "contaazul/error"
4
+ require "contaazul/client"
5
+
6
+ module Contaazul
7
+ extend Configuration
8
+ class <<self
9
+ # Alias for Contaazul::Client.new
10
+ #
11
+ # @return [Contaazul::Client]
12
+ def new(options = {})
13
+ Contaazul::Client.new(options)
14
+ end
15
+
16
+ def method_missing(method, *args, &block)
17
+ return super unless new.respond_to?(method)
18
+ new.send(method, *args, &block)
19
+ end
20
+
21
+ def respond_to?(method, include_private = false)
22
+ new.respond_to?(method, include_private) || super(method, include_private)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ module Contaazul
2
+ module Authentication
3
+ def authentication
4
+ if login && password
5
+ {:login => login, :password => password}
6
+ else
7
+ {}
8
+ end
9
+ end
10
+
11
+ def authenticated?
12
+ !authentication.empty?
13
+ end
14
+
15
+ def oauthed?
16
+ !oauth_token.nil?
17
+ end
18
+
19
+ def unauthed_rate_limited?
20
+ client_id && client_secret
21
+ end
22
+
23
+ def unauthed_rate_limit_params
24
+ {
25
+ :client_id => client_id,
26
+ :client_secret => client_secret
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'contaazul/authentication'
2
+ # require 'contaazul/connection'
3
+ # require 'contaazul/repository'
4
+ # require 'contaazul/request'
5
+
6
+ # require 'contaazul/client/github'
7
+
8
+ module Contaazul
9
+ class Client
10
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
11
+
12
+ def initialize(options = {})
13
+ options = Contaazul.options.merge(options)
14
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+
18
+ end
19
+
20
+ include Contaazul::Authentication
21
+ # include Contaazul::Connection
22
+ # include Contaazul::Request
23
+
24
+ # include Contaazul::Client::GitHub
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ require 'faraday'
2
+ require 'contaazul/version'
3
+
4
+ module Contaazul
5
+ module Configuration
6
+ VALID_OPTIONS_KEYS = [
7
+ :adapter,
8
+ :faraday_config_block,
9
+ :api_version,
10
+ :api_endpoint,
11
+ :login,
12
+ :password,
13
+ :proxy,
14
+ :oauth_token,
15
+ :client_id,
16
+ :client_secret,
17
+ :user_agent,
18
+ :request_host,
19
+ :netrc,
20
+ :auto_traversal,
21
+ :per_page].freeze
22
+
23
+ DEFAULT_ADAPTER = Faraday.default_adapter
24
+ DEFAULT_API_VERSION = 3
25
+ DEFAULT_API_ENDPOINT = ENV['CONTAAZUL_API_ENDPOINT'] || 'http://api.contaazul.com.br/'
26
+ DEFAULT_USER_AGENT = "Contaazul Non-Official Ruby Gem #{Contaazul::VERSION}".freeze
27
+ DEFAULT_AUTO_TRAVERSAL = false
28
+
29
+ attr_accessor(*VALID_OPTIONS_KEYS)
30
+
31
+ def self.extended(base)
32
+ base.reset
33
+ end
34
+
35
+ def configure
36
+ yield self
37
+ end
38
+
39
+ def options
40
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
41
+ end
42
+
43
+ def api_endpoint=(value)
44
+ @api_endpoint = File.join(value, "")
45
+ end
46
+
47
+ def faraday_config(&block)
48
+ @faraday_config_block = block
49
+ end
50
+
51
+ def reset
52
+ self.adapter = DEFAULT_ADAPTER
53
+ self.api_version = DEFAULT_API_VERSION
54
+ self.api_endpoint = DEFAULT_API_ENDPOINT
55
+ self.login = nil
56
+ self.password = nil
57
+ self.proxy = nil
58
+ self.oauth_token = nil
59
+ self.client_id = nil
60
+ self.client_secret = nil
61
+ self.request_host = nil
62
+ self.netrc = false
63
+ self.user_agent = DEFAULT_USER_AGENT
64
+ self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,68 @@
1
+ module Contaazul
2
+ # Custom error class for rescuing from all Contaazul API errors
3
+ class Error < StandardError
4
+ def initialize(response=nil)
5
+ @response = response
6
+ super(build_error_message)
7
+ end
8
+
9
+ def response_body
10
+ @response_body ||=
11
+ if (body = @response[:body]) && !body.empty?
12
+ if body.is_a?(String)
13
+ MultiJson.load(body, :symbolize_keys => true)
14
+ else
15
+ body
16
+ end
17
+ else
18
+ nil
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def build_error_message
25
+ return nil if @response.nil?
26
+
27
+ message = if response_body
28
+ ": #{response_body[:error] || response_body[:message] || ''}"
29
+ else
30
+ ''
31
+ end
32
+ errors = unless message.empty?
33
+ response_body[:errors] ? ": #{response_body[:errors].map{|e|e[:message]}.join(', ')}" : ''
34
+ end
35
+ "#{@response[:method].to_s.upcase} #{@response[:url].to_s}: #{@response[:status]}#{message}#{errors}"
36
+ end
37
+ end
38
+
39
+ # Raised when Contaazul API returns a 400 HTTP status code
40
+ class BadRequest < Error; end
41
+
42
+ # Raised when Contaazul API returns a 401 HTTP status code
43
+ class Unauthorized < Error; end
44
+
45
+ # Raised when Contaazul API returns a 403 HTTP status code
46
+ class Forbidden < Error; end
47
+
48
+ # Raised when Contaazul API returns a 404 HTTP status code
49
+ class NotFound < Error; end
50
+
51
+ # Raised when Contaazul API returns a 406 HTTP status code
52
+ class NotAcceptable < Error; end
53
+
54
+ # Raised when Contaazul API returns a 422 HTTP status code
55
+ class UnprocessableEntity < Error; end
56
+
57
+ # Raised when Contaazul API returns a 500 HTTP status code
58
+ class InternalServerError < Error; end
59
+
60
+ # Raised when Contaazul API returns a 501 HTTP status code
61
+ class NotImplemented < Error; end
62
+
63
+ # Raised when Contaazul API returns a 502 HTTP status code
64
+ class BadGateway < Error; end
65
+
66
+ # Raised when Contaazul API returns a 503 HTTP status code
67
+ class ServiceUnavailable < Error; end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Contaazul
2
+ VERSION = "0.1.0dev"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Contaazul do
5
+ after do
6
+ Contaazul.reset
7
+ end
8
+
9
+ describe ".respond_to?" do
10
+ it "is true if method exists" do
11
+ expect(Contaazul.respond_to?(:new, true)).to eq(true)
12
+ end
13
+ end
14
+
15
+ describe ".new" do
16
+ it "is a Contaazul::Client" do
17
+ expect(Contaazul.new).to be_a Contaazul::Client
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,82 @@
1
+ require 'contaazul'
2
+ require 'rspec'
3
+ require 'webmock/rspec'
4
+
5
+ WebMock.disable_net_connect!
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
12
+
13
+ def a_delete(url)
14
+ a_request(:delete, contaazul_url(url))
15
+ end
16
+
17
+ def a_get(url)
18
+ a_request(:get, contaazul_url(url))
19
+ end
20
+
21
+ def a_patch(url)
22
+ a_request(:patch, contaazul_url(url))
23
+ end
24
+
25
+ def a_post(url)
26
+ a_request(:post, contaazul_url(url))
27
+ end
28
+
29
+ def a_put(url)
30
+ a_request(:put, contaazul_url(url))
31
+ end
32
+
33
+ def stub_delete(url)
34
+ stub_request(:delete, contaazul_url(url))
35
+ end
36
+
37
+ def stub_get(url)
38
+ stub_request(:get, contaazul_url(url))
39
+ end
40
+
41
+ def stub_head(url)
42
+ stub_request(:head, contaazul_url(url))
43
+ end
44
+
45
+ def stub_patch(url)
46
+ stub_request(:patch, contaazul_url(url))
47
+ end
48
+
49
+ def stub_post(url)
50
+ stub_request(:post, contaazul_url(url))
51
+ end
52
+
53
+ def stub_put(url)
54
+ stub_request(:put, contaazul_url(url))
55
+ end
56
+
57
+ def fixture_path
58
+ File.expand_path("../fixtures", __FILE__)
59
+ end
60
+
61
+ def fixture(file)
62
+ File.new(fixture_path + '/' + file)
63
+ end
64
+
65
+ def json_response(file)
66
+ {
67
+ :body => fixture(file),
68
+ :headers => {
69
+ :content_type => 'application/json; charset=utf-8'
70
+ }
71
+ }
72
+ end
73
+
74
+ def contaazul_url(url)
75
+ if url =~ /^http/
76
+ url
77
+ elsif @client && @client.authenticated?
78
+ "http://api.contaazul.com.br/pub#{url}"
79
+ else
80
+ "http://api.contaazul.com.br#{url}"
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contaazul
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0dev
5
+ platform: ruby
6
+ authors:
7
+ - João Netto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: multi_json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.7.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.7.6
83
+ description: A tiny non-official wrapper for ContaAzul's API
84
+ email:
85
+ - hi@joaonetto.me
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.md
94
+ - README.md
95
+ - Rakefile
96
+ - contaazul.gemspec
97
+ - lib/contaazul.rb
98
+ - lib/contaazul/authentication.rb
99
+ - lib/contaazul/client.rb
100
+ - lib/contaazul/configuration.rb
101
+ - lib/contaazul/error.rb
102
+ - lib/contaazul/version.rb
103
+ - spec/contaazul_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/jnettome/contaazul
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '1.8'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Integrate your ruby app with ContaAzul's API (contaazul.com.br)
129
+ test_files:
130
+ - spec/contaazul_spec.rb
131
+ - spec/spec_helper.rb
132
+ has_rdoc: