flow_account_ruby 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flow_account.gemspec +31 -0
- data/lib/faraday/loud_logger.rb +75 -0
- data/lib/faraday/oauth2.rb +40 -0
- data/lib/faraday/raise_http_exception.rb +59 -0
- data/lib/flow_account/api.rb +28 -0
- data/lib/flow_account/auth.rb +33 -0
- data/lib/flow_account/client/purchase_order.rb +12 -0
- data/lib/flow_account/client/tax_invoice.rb +23 -0
- data/lib/flow_account/client.rb +8 -0
- data/lib/flow_account/configuration.rb +72 -0
- data/lib/flow_account/connection.rb +29 -0
- data/lib/flow_account/error.rb +31 -0
- data/lib/flow_account/request.rb +37 -0
- data/lib/flow_account/response.rb +10 -0
- data/lib/flow_account/version.rb +3 -0
- data/lib/flow_account.rb +26 -0
- data/lib/new_purchase_order.json +47 -0
- data/lib/new_tax_invoice.json +59 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 991bc96abab8e977513efa79bc6ba773aa6dfe66
|
4
|
+
data.tar.gz: ea1457f42e20eec65fd6cd0af54099b3dd795413
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77cdc5d71053c374c4b37ddf49c256ca77d99bb239d11c316af9b92d58172bafb217d0732e86aa40aa2de364fbcafab588b00398b4657bbb09dca435b5e248e2
|
7
|
+
data.tar.gz: 2eea936ee4cafa0f305f556035e7ae3eeafb52d8248e9f5d91a2707d3d5af99507eff306d00d9d98d21decabf0f39f6725e51eceeff07ef671b38c256ba93c51
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at chiragrajk@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 ChiragRajk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# FlowAccount
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flow_account`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'flow_account_ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flow_account_ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
FlowAccount.configure do |config|
|
27
|
+
config.client_id = 'a_client_id'
|
28
|
+
config.client_secret = 'a_client_secret'
|
29
|
+
config.loud_logger = true # for development logging
|
30
|
+
end
|
31
|
+
|
32
|
+
token = FlowAccount.get_access_token
|
33
|
+
client = FlowAccount.client(access_token: token)
|
34
|
+
client.tax_invoices # get all tax-invoices
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/flow_account. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flow_account"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flow_account/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flow_account_ruby"
|
8
|
+
spec.version = FlowAccount::VERSION
|
9
|
+
spec.authors = ["Chirag Rajkarnikar"]
|
10
|
+
spec.email = ["chiragrajk@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby wrapper for the Flow Account API}
|
13
|
+
spec.description = %q{A Ruby wrapper for the Flow Account REST APIs}
|
14
|
+
spec.homepage = "https://github.com/connectica/flow_account/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
28
|
+
spec.add_runtime_dependency 'faraday', '~> 0.12'
|
29
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 0.11'
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class LoudLogger < Faraday::Middleware
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
9
|
+
|
10
|
+
def initialize(app, options = {})
|
11
|
+
@app = app
|
12
|
+
@logger = options.fetch(:logger) {
|
13
|
+
require 'logger'
|
14
|
+
::Logger.new($stdout)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
start_time = Time.now
|
20
|
+
info { request_info(env) }
|
21
|
+
debug { request_debug(env) }
|
22
|
+
@app.call(env).on_complete do
|
23
|
+
end_time = Time.now
|
24
|
+
response_time = end_time - start_time
|
25
|
+
info { response_info(env, response_time) }
|
26
|
+
debug { response_debug(env) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def filter(output)
|
33
|
+
if ENV['INSTAGRAM_GEM_REDACT']
|
34
|
+
output = output.to_s.gsub(/client_id=[a-zA-Z0-9]*/,'client_id=[CLIENT-ID]')
|
35
|
+
output = output.to_s.gsub(/access_token=[a-zA-Z0-9]*/,'access_token=[ACCESS-TOKEN]')
|
36
|
+
else
|
37
|
+
output
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def request_info(env)
|
42
|
+
"Started %s request to: %s" % [ env[:method].to_s.upcase, filter(env[:url]) ]
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_info(env, response_time)
|
46
|
+
"Response from %s; Status: %d; Time: %.1fms" % [ filter(env[:url]), env[:status], (response_time * 1_000.0) ]
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_debug(env)
|
50
|
+
debug_message("Request", env[:request_headers], env[:body])
|
51
|
+
end
|
52
|
+
|
53
|
+
def response_debug(env)
|
54
|
+
debug_message("Response", env[:response_headers], env[:body])
|
55
|
+
end
|
56
|
+
|
57
|
+
def debug_message(name, headers, body)
|
58
|
+
<<-MESSAGE.gsub(/^ +([^ ])/m, '\\1')
|
59
|
+
#{name} Headers:
|
60
|
+
----------------
|
61
|
+
#{format_headers(headers)}
|
62
|
+
|
63
|
+
#{name} Body:
|
64
|
+
-------------
|
65
|
+
#{filter(body)}
|
66
|
+
MESSAGE
|
67
|
+
end
|
68
|
+
|
69
|
+
def format_headers(headers)
|
70
|
+
length = headers.map {|k,v| k.to_s.size }.max
|
71
|
+
headers.map { |name, value| "#{name.to_s.ljust(length)} : #{filter(value)}" }.join("\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module FaradayMiddleware
|
5
|
+
class FlowAccountOAuth2 < Faraday::Middleware
|
6
|
+
def call(env)
|
7
|
+
if env[:method] == :get or env[:method] == :delete
|
8
|
+
if env[:url].query.nil?
|
9
|
+
query = {}
|
10
|
+
else
|
11
|
+
query = Faraday::Utils.parse_query(env[:url].query)
|
12
|
+
end
|
13
|
+
|
14
|
+
if @access_token and not query["client_secret"]
|
15
|
+
env[:request_headers] = env[:request_headers].merge("Authorization" => "Bearer #{@access_token}")
|
16
|
+
end
|
17
|
+
else # :POST, :PUT
|
18
|
+
if @access_token and not env[:body] && JSON.parse(env[:body])["client_secret"]
|
19
|
+
env[:body] = {} if env[:body].nil?
|
20
|
+
env[:request_headers] = env[:request_headers].merge(
|
21
|
+
"Authorization" => "Bearer " + @access_token,
|
22
|
+
"Content-Type" => "application/json"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@app.call env
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(app, client_id, access_token=nil)
|
31
|
+
@app = app
|
32
|
+
@client_id = client_id
|
33
|
+
@access_token = access_token
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# request.headers['Authorization'] = "Bearer " + access_token
|
40
|
+
# request.headers['Content-Type'] = "application/json"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class RaiseHttpException < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
case response[:status].to_i
|
10
|
+
when 400
|
11
|
+
raise FlowAccount::BadRequest, error_message_400(response)
|
12
|
+
when 404
|
13
|
+
raise FlowAccount::NotFound, error_message_400(response)
|
14
|
+
when 429
|
15
|
+
raise FlowAccount::TooManyRequests, error_message_400(response)
|
16
|
+
when 500
|
17
|
+
raise FlowAccount::InternalServerError, error_message_500(response, "Something is technically wrong.")
|
18
|
+
when 502
|
19
|
+
raise FlowAccount::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
|
20
|
+
when 503
|
21
|
+
raise FlowAccount::ServiceUnavailable, error_message_500(response, "FlowAccount is rate limiting your requests.")
|
22
|
+
when 504
|
23
|
+
raise FlowAccount::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(app)
|
29
|
+
super app
|
30
|
+
@parser = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def error_message_400(response)
|
36
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def error_body(body)
|
40
|
+
# body gets passed as a string, not sure if it is passed as something else from other spots?
|
41
|
+
if not body.nil? and not body.empty? and body.kind_of?(String)
|
42
|
+
# removed multi_json thanks to wesnolte's commit
|
43
|
+
body = ::JSON.parse(body)
|
44
|
+
end
|
45
|
+
|
46
|
+
if body.nil?
|
47
|
+
nil
|
48
|
+
elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
|
49
|
+
": #{body['meta']['error_message']}"
|
50
|
+
elsif body['error_message'] and not body['error_message'].empty?
|
51
|
+
": #{body['error_type']}: #{body['error_message']}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def error_message_500(response, body=nil)
|
56
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
require File.expand_path('../auth', __FILE__)
|
4
|
+
|
5
|
+
module FlowAccount
|
6
|
+
class API
|
7
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
options = FlowAccount.options.merge(options)
|
11
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
12
|
+
send("#{key}=", options[key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
conf = {}
|
18
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
19
|
+
conf[key] = send key
|
20
|
+
end
|
21
|
+
conf
|
22
|
+
end
|
23
|
+
|
24
|
+
include Connection
|
25
|
+
include Request
|
26
|
+
include Auth
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module FlowAccount
|
2
|
+
module Auth
|
3
|
+
def get_access_token(options={})
|
4
|
+
options[:grant_type] ||= "client_credentials"
|
5
|
+
options[:scope] ||= scope if !scope.nil? && !scope.empty?
|
6
|
+
|
7
|
+
params = access_token_params.merge(options)
|
8
|
+
post("token", params, raw=false, no_response_wrapper=true)
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorize_url(options={})
|
12
|
+
options[:scope] ||= scope if !scope.nil? && !scope.empty?
|
13
|
+
|
14
|
+
params = authorization_params.merge(options)
|
15
|
+
connection.build_url("token", params).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def access_token_params
|
20
|
+
{
|
21
|
+
client_id: client_id,
|
22
|
+
client_secret: client_secret
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def authorization_params
|
27
|
+
{
|
28
|
+
client_id: client_id,
|
29
|
+
scope: scope
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FlowAccount
|
2
|
+
class Client
|
3
|
+
module TaxInvoice
|
4
|
+
|
5
|
+
def create_tax_invoice(params)
|
6
|
+
post('tax-invoices', params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tax_invoice(id)
|
10
|
+
get("tax-invoices/#{id}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def tax_invoices(offset=0, limit=10)
|
14
|
+
get("tax-invoices", {offset: offset, limit: limit})
|
15
|
+
end
|
16
|
+
|
17
|
+
def tax_invoice_link(id, lang=:en)
|
18
|
+
get("tax-invoices/#{id}/#{lang}/share-link")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
module FlowAccount
|
6
|
+
module Configuration
|
7
|
+
|
8
|
+
DEFAULT_ACCESS_TOKEN = nil
|
9
|
+
DEFAULT_CLIENT_ID = nil
|
10
|
+
DEFAULT_CLIENT_SECRET = nil
|
11
|
+
DEFAULT_SCOPE = 'flowaccount-api'
|
12
|
+
DEFAULT_USER_AGENT = "Flow Account Ruby Gem #{FlowAccount::VERSION}".freeze
|
13
|
+
DEFAULT_FORMAT = :json
|
14
|
+
DEFAULT_LOUD_LOGGER = nil
|
15
|
+
DEFAULT_CONNECTION_OPTIONS = {}
|
16
|
+
|
17
|
+
# By default, don't wrap responses with meta data (i.e. pagination)
|
18
|
+
DEFAULT_NO_RESPONSE_WRAPPER = false
|
19
|
+
|
20
|
+
# The adapter that will be used to connect if none is set
|
21
|
+
#
|
22
|
+
# @note The default faraday adapter is Net::HTTP.
|
23
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
24
|
+
|
25
|
+
DEFAULT_ENDPOINT = 'https://qyedkbf6yd.execute-api.ap-southeast-1.amazonaws.com/dev/'.freeze
|
26
|
+
# DEFAULT_ENDPOINT = 'http://localhost:3000/'.freeze
|
27
|
+
|
28
|
+
VALID_OPTIONS_KEYS = [
|
29
|
+
:access_token,
|
30
|
+
:client_id,
|
31
|
+
:client_secret,
|
32
|
+
:scope,
|
33
|
+
:endpoint,
|
34
|
+
:user_agent,
|
35
|
+
:connection_options,
|
36
|
+
:format,
|
37
|
+
:loud_logger,
|
38
|
+
:adapter,
|
39
|
+
:no_response_wrapper
|
40
|
+
]
|
41
|
+
|
42
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
43
|
+
|
44
|
+
def options
|
45
|
+
VALID_OPTIONS_KEYS.inject({}) do |options, key|
|
46
|
+
options.merge!(key => send(key))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def configure
|
51
|
+
yield self
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.extended(base)
|
55
|
+
base.reset
|
56
|
+
end
|
57
|
+
|
58
|
+
def reset
|
59
|
+
self.access_token = DEFAULT_ACCESS_TOKEN
|
60
|
+
self.client_id = DEFAULT_CLIENT_ID
|
61
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
62
|
+
self.scope = DEFAULT_SCOPE
|
63
|
+
self.user_agent = DEFAULT_USER_AGENT
|
64
|
+
self.format = DEFAULT_FORMAT
|
65
|
+
self.loud_logger = DEFAULT_LOUD_LOGGER
|
66
|
+
self.adapter = DEFAULT_ADAPTER
|
67
|
+
self.endpoint = DEFAULT_ENDPOINT
|
68
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
69
|
+
self.no_response_wrapper= DEFAULT_NO_RESPONSE_WRAPPER
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
3
|
+
|
4
|
+
module FlowAccount
|
5
|
+
module Connection
|
6
|
+
|
7
|
+
private
|
8
|
+
def connection(raw=false)
|
9
|
+
options = {
|
10
|
+
headers: { 'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
|
11
|
+
url: endpoint
|
12
|
+
}.merge(connection_options)
|
13
|
+
|
14
|
+
Faraday::Connection.new(options) do |connection|
|
15
|
+
connection.use FaradayMiddleware::FlowAccountOAuth2, client_id, access_token
|
16
|
+
connection.use Faraday::Request::UrlEncoded
|
17
|
+
connection.use FaradayMiddleware::Mashify unless raw
|
18
|
+
unless raw
|
19
|
+
case format.to_s.downcase
|
20
|
+
when 'json' then connection.use Faraday::Response::ParseJson
|
21
|
+
end
|
22
|
+
end
|
23
|
+
connection.use FaradayMiddleware::RaiseHttpException
|
24
|
+
connection.use FaradayMiddleware::LoudLogger if loud_logger
|
25
|
+
connection.adapter(adapter)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module FlowAccount
|
2
|
+
# Custom error class for rescuing from all FlowAccount errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when FlowAccount returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when FlowAccount returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when FlowAccount returns the HTTP status code 429
|
12
|
+
class TooManyRequests < Error; end
|
13
|
+
|
14
|
+
# Raised when FlowAccount returns the HTTP status code 500
|
15
|
+
class InternalServerError < Error; end
|
16
|
+
|
17
|
+
# Raised when FlowAccount returns the HTTP status code 502
|
18
|
+
class BadGateway < Error; end
|
19
|
+
|
20
|
+
# Raised when FlowAccount returns the HTTP status code 503
|
21
|
+
class ServiceUnavailable < Error; end
|
22
|
+
|
23
|
+
# Raised when FlowAccount returns the HTTP status code 504
|
24
|
+
class GatewayTimeout < Error; end
|
25
|
+
|
26
|
+
# Raised when a subscription payload hash is invalid
|
27
|
+
class InvalidSignature < Error; end
|
28
|
+
|
29
|
+
# Raised when FlowAccount returns the HTTP status code 429
|
30
|
+
class RateLimitExceeded < Error; end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FlowAccount
|
2
|
+
module Request
|
3
|
+
|
4
|
+
def post(path, options={}, raw=false, no_response_wrapper=no_response_wrapper())
|
5
|
+
request(:post, path, options, raw, no_response_wrapper)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(path, options={}, raw=false, no_response_wrapper=no_response_wrapper())
|
9
|
+
request(:get, path, options, raw, no_response_wrapper)
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(path, options={}, raw=false, no_response_wrapper=no_response_wrapper())
|
13
|
+
request(:put, path, options, raw, no_response_wrapper)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(path, options={}, raw=false, no_response_wrapper=no_response_wrapper())
|
17
|
+
request(:delete, path, options, raw, no_response_wrapper)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def request(method, path, options, raw=false, no_response_wrapper=false)
|
22
|
+
response = connection(raw).send(method) do |request|
|
23
|
+
case method
|
24
|
+
when :get, :delete
|
25
|
+
request.url(URI.encode(path), options)
|
26
|
+
when :post, :put
|
27
|
+
request.path = URI.encode(path)
|
28
|
+
request.body = options unless options.empty?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return response if raw
|
32
|
+
return response.body if no_response_wrapper
|
33
|
+
return Response.create(response.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/flow_account.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "flow_account/version"
|
2
|
+
|
3
|
+
require "flow_account/error"
|
4
|
+
require "flow_account/configuration"
|
5
|
+
require "flow_account/api"
|
6
|
+
require "flow_account/client"
|
7
|
+
require "flow_account/response"
|
8
|
+
|
9
|
+
module FlowAccount
|
10
|
+
extend Configuration
|
11
|
+
|
12
|
+
def self.client(options={})
|
13
|
+
FlowAccount::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to FlowAccount::Client
|
17
|
+
def self.method_missing(method, *args, &block)
|
18
|
+
return super unless client.respond_to?(method)
|
19
|
+
client.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delegate to FlowAccount::Client
|
23
|
+
def self.respond_to?(method, include_all=false)
|
24
|
+
return client.respond_to?(method, include_all) || super
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
{
|
2
|
+
"invoiceName": "Create Pruchase Order",
|
3
|
+
"reference": "reference Purchase oreder",
|
4
|
+
"publishedOn": "2017-02-14T00:00:00Z",
|
5
|
+
"CreditDays": 0,
|
6
|
+
"DueDate": "2017-02-14T00:00:00Z",
|
7
|
+
"Status": 1,
|
8
|
+
"IsVat": "true",
|
9
|
+
"vATRate": "7",
|
10
|
+
"IsDicountAsPercentage": false,
|
11
|
+
"Discount": 0.00,
|
12
|
+
"DiscountPercentage": 0.00,
|
13
|
+
"Remarks": "remark Purchase oreder",
|
14
|
+
"InternalNotes":"Test internal note",
|
15
|
+
"ClientName": "flowaccount Purchase oreder",
|
16
|
+
"ClientAddress": "155",
|
17
|
+
"ClientAddressLine2": "dfdf2",
|
18
|
+
"ClientAddressLine3": "dfdf3",
|
19
|
+
"ClientTaxId": "12345-66666-777",
|
20
|
+
"ClientBranch": "branch name",
|
21
|
+
"ContactNumber": "0911111111",
|
22
|
+
"ContactPerson": "kriangsak_tak",
|
23
|
+
"ContactEmail": "public-api-uteeni@flowaccount.com",
|
24
|
+
"salesName": "public-api-uteeni@flowaccount.com",
|
25
|
+
"Total": 102.72,
|
26
|
+
"ProductItems": [{
|
27
|
+
"Name": "product Purchase oreder -1",
|
28
|
+
"PricePerUnit": 30.00,
|
29
|
+
"Quantity": 1.00,
|
30
|
+
"Description": "description product 1 Purchase oreder",
|
31
|
+
"Barcode": "barcode-*859",
|
32
|
+
"Productcode": "sku-11111",
|
33
|
+
"No": 0,
|
34
|
+
"Type": 3
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"Name": "product Purchase oreder -2",
|
38
|
+
"PricePerUnit": 15.00,
|
39
|
+
"Quantity": 10.00,
|
40
|
+
"Description": "description product 2 Purchase oreder",
|
41
|
+
"Barcode": "77-658s5df",
|
42
|
+
"Productcode": "sku-0000001",
|
43
|
+
"No": 1,
|
44
|
+
"Type": 3
|
45
|
+
}
|
46
|
+
]
|
47
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"invoiceName": "Create Document",
|
3
|
+
"reference": "reference Document",
|
4
|
+
"publishedOn": "2017-02-14T00:00:00Z",
|
5
|
+
"CreditDays": 0,
|
6
|
+
"DueDate": "2017-02-14T00:00:00Z",
|
7
|
+
"Status": 5,
|
8
|
+
"IsVat": "true",
|
9
|
+
"vATRate": "7",
|
10
|
+
"IsDicountAsPercentage": false,
|
11
|
+
"Discount": 0.00,
|
12
|
+
"DiscountPercentage": 0.00,
|
13
|
+
"DocumentSerialPOS": "test document serial pos",
|
14
|
+
"Remarks": "remark Document",
|
15
|
+
"InternalNotes":"Test internal note",
|
16
|
+
"ClientName": "flowaccount Document",
|
17
|
+
"ClientAddress": "155",
|
18
|
+
"ClientAddressLine2": "dfdf2",
|
19
|
+
"ClientAddressLine3": "dfdf3",
|
20
|
+
"ClientTaxId": "12345-66666-777",
|
21
|
+
"ClientBranch": "branch name",
|
22
|
+
"ContactNumber": "0911111111",
|
23
|
+
"ContactPerson": "kriangsak_tak",
|
24
|
+
"ContactEmail": "public-api-uteeni@flowaccount.com",
|
25
|
+
"salesName": "public-api-uteeni@flowaccount.com",
|
26
|
+
"Total": 102.72,
|
27
|
+
"ProductItems": [{
|
28
|
+
"Name": "product Document 1",
|
29
|
+
"PricePerUnit": 30.00,
|
30
|
+
"Quantity": 1.00,
|
31
|
+
"Description": "description product 1 update Document",
|
32
|
+
"Barcode": "barcode-*859",
|
33
|
+
"Productcode": "sku-11111",
|
34
|
+
"No": 0,
|
35
|
+
"Type": 3
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"Name": "product Document 2",
|
39
|
+
"PricePerUnit": 15.00,
|
40
|
+
"Quantity": 10.00,
|
41
|
+
"Description": "description product 2 update Document",
|
42
|
+
"Barcode": "77-658s5df",
|
43
|
+
"Productcode": "sku-0000001",
|
44
|
+
"No": 1,
|
45
|
+
"Type": 3
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"MethodPayment": 5,
|
49
|
+
"DatePayment": "2017-02-14T00:00:00Z",
|
50
|
+
"CheckDatePaid " : "2017-02-14T00:00:00Z",
|
51
|
+
"TransferBankId": "",
|
52
|
+
"CheckBankId" : "Name bank",
|
53
|
+
"CheckNumber": "1234",
|
54
|
+
"WithHeld": 11,
|
55
|
+
"Collected": 20.00,
|
56
|
+
"Tax": 3,
|
57
|
+
"Charge": 20.00,
|
58
|
+
"PaymentRemarks": "test paymentRemarks"
|
59
|
+
}
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flow_account_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chirag Rajkarnikar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-04 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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.12'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.12'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday_middleware
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.11'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.11'
|
97
|
+
description: A Ruby wrapper for the Flow Account REST APIs
|
98
|
+
email:
|
99
|
+
- chiragrajk@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- flow_account.gemspec
|
115
|
+
- lib/faraday/loud_logger.rb
|
116
|
+
- lib/faraday/oauth2.rb
|
117
|
+
- lib/faraday/raise_http_exception.rb
|
118
|
+
- lib/flow_account.rb
|
119
|
+
- lib/flow_account/api.rb
|
120
|
+
- lib/flow_account/auth.rb
|
121
|
+
- lib/flow_account/client.rb
|
122
|
+
- lib/flow_account/client/purchase_order.rb
|
123
|
+
- lib/flow_account/client/tax_invoice.rb
|
124
|
+
- lib/flow_account/configuration.rb
|
125
|
+
- lib/flow_account/connection.rb
|
126
|
+
- lib/flow_account/error.rb
|
127
|
+
- lib/flow_account/request.rb
|
128
|
+
- lib/flow_account/response.rb
|
129
|
+
- lib/flow_account/version.rb
|
130
|
+
- lib/new_purchase_order.json
|
131
|
+
- lib/new_tax_invoice.json
|
132
|
+
homepage: https://github.com/connectica/flow_account/
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.5.1
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Ruby wrapper for the Flow Account API
|
156
|
+
test_files: []
|