colppy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 423516e6c9f241cf1d2e7ddaa3dc32bacf8ed356
4
+ data.tar.gz: ccb895a2d95fa3f55b3f2a97f7b0c21743d5c182
5
+ SHA512:
6
+ metadata.gz: 59f62eb828dd05967ff21e9d567c39cc8830bd2f3820f9bd331b7f0ae27cc5c0a20d4745c92d82d339c434188b08b330a31e84ab60e8d1a741ed9d34acde72c2
7
+ data.tar.gz: 07f3ee5c00ac9e8a79630911765013709fe07fffb1095dc99e8587b6fa0d2d07c8330cef152db5aa2963e7fa32c369257baf9e7a180b541710be4fe1c4ffb208
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,36 @@
1
+ Metrics/BlockNesting:
2
+ Max: 2
3
+
4
+ Metrics/LineLength:
5
+ AllowURI: true
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ CountComments: false
10
+ Max: 10
11
+
12
+ Metrics/ParameterLists:
13
+ Max: 4
14
+ CountKeywordArgs: true
15
+
16
+ Style/CollectionMethods:
17
+ PreferredMethods:
18
+ collect: 'map'
19
+ reduce: 'inject'
20
+ find: 'detect'
21
+ find_all: 'select'
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ Style/DoubleNegation:
27
+ Enabled: false
28
+
29
+ Style/SpaceInsideHashLiteralBraces:
30
+ EnforcedStyle: no_space
31
+
32
+ Style/StringLiterals:
33
+ EnforcedStyle: double_quotes
34
+
35
+ Style/BracesAroundHashParameters:
36
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.2.5
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.6
5
+ - 2.2.5
6
+ - 2.3.1
7
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at cavi21@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :test do
4
+ gem "coveralls"
5
+ gem "rubocop", ">= 0.30", platforms: [:ruby_21, :ruby_22, :ruby_23]
6
+ gem "simplecov", ">= 0.9"
7
+ end
8
+
9
+ # Specify your gem's dependencies in colppy.gemspec
10
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Agustin Cavilliotti
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.
@@ -0,0 +1,38 @@
1
+ #Colppy
2
+ [![Build Status](https://travis-ci.org/goodpeople/colppy.svg?branch=master)](https://travis-ci.org/goodpeople/colppy)
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'colppy'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install colppy
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ 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).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/goodpeople/colppy. 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.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
@@ -0,0 +1,39 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ begin
11
+ require "rubocop/rake_task"
12
+ RuboCop::RakeTask.new
13
+ rescue LoadError
14
+ task :rubocop do
15
+ $stderr.puts "RuboCop is disabled"
16
+ end
17
+ end
18
+
19
+ # task default: [:test, :rubocop]
20
+ task default: [:test]
21
+
22
+ task :console do
23
+ require "pry"
24
+ require "./lib/colppy"
25
+ require "httplog"
26
+
27
+ def reload!
28
+ files = $LOADED_FEATURES.select { |feat| feat =~ %r{lib/colppy} }
29
+ # Deactivate warning messages.
30
+ original_verbose, $VERBOSE = $VERBOSE, nil
31
+ files.each { |file| load file }
32
+ # Activate warning messages again.
33
+ $VERBOSE = original_verbose
34
+ "Console reloaded!"
35
+ end
36
+
37
+ ARGV.clear
38
+ Pry.start
39
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "colppy"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "colppy/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "colppy"
8
+ spec.version = Colppy::VERSION
9
+ spec.authors = ["Agustin Cavilliotti"]
10
+ spec.email = ["cavi21@gmail.com"]
11
+
12
+ spec.summary = "Client to interact with Colppy API"
13
+ spec.description = "Allow to interact with the services available on the Colppy API (https://colppy.atlassian.net/wiki/display/CA/Bienvenidos+-+Colppy+API)"
14
+ spec.homepage = "https://github.com/goodpeople/colppy"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "faraday", [">= 0.8", "< 0.10"]
23
+ spec.add_dependency "multi_json", "~> 1.3"
24
+
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "httplog"
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ end
@@ -0,0 +1,22 @@
1
+ # SUPPORT LIBS
2
+ require 'faraday'
3
+ require 'multi_json'
4
+
5
+ require "colppy/version"
6
+ require "colppy/digest"
7
+ # CORE
8
+ require "colppy/core/services"
9
+ require "colppy/core/gateway"
10
+ # RESOURCES
11
+ require "colppy/resource"
12
+ require "colppy/resources/customer"
13
+ require "colppy/resources/company"
14
+ require "colppy/resources/product"
15
+ require "colppy/resources/sell_invoice"
16
+ require "colppy/resources/user"
17
+ # CLIENT
18
+ require "colppy/errors"
19
+ require "colppy/client"
20
+
21
+ module Colppy
22
+ end
@@ -0,0 +1,69 @@
1
+ module Colppy
2
+ class Client
3
+ include Digest
4
+ SERVICES_MANIFEST = Core::SERVICES.freeze
5
+
6
+ def initialize(auth_user, auth_pass, user)
7
+ ensure_user_valid!(user)
8
+
9
+ @auth_user = auth_user
10
+ @auth_pass = md5(auth_pass)
11
+ @gateway = Core::Gateway.new
12
+ if user
13
+ @user = user
14
+ sign_in
15
+ end
16
+ end
17
+
18
+ def inspect
19
+ formatted_attrs = attr_inspect.map do |attr|
20
+ "#{attr}: #{send(attr).inspect}"
21
+ end
22
+ "#<#{self.class.name} #{formatted_attrs.join(", ")}>"
23
+ end
24
+
25
+ include CompanyActions
26
+ include UserActions
27
+
28
+ def call(service, operation, params)
29
+ request_payload = request_base(service, operation).merge(parameters: params)
30
+
31
+ @gateway.call(request_payload)[:response] if request_payload
32
+ end
33
+
34
+ private
35
+
36
+ def attr_inspect
37
+ [:session_key]
38
+ end
39
+
40
+ def request_base(service, operation)
41
+ service = request_for!(service, operation)
42
+
43
+ {
44
+ auth: {
45
+ usuario: @auth_user,
46
+ password: @auth_pass
47
+ },
48
+ service: service
49
+ }
50
+ end
51
+
52
+ def request_for!(service, operation)
53
+ unless SERVICES_MANIFEST.keys.include?(service)
54
+ error = "There is no :#{service} service. The available ones are: " \
55
+ "[:#{SERVICES_MANIFEST.keys.join(', :')}]"
56
+ raise ServiceError.new(error)
57
+ end
58
+ service = SERVICES_MANIFEST[service]
59
+
60
+ unless service.keys.include?(operation)
61
+ error = "There is no operation called :#{operation}. The available operations are: "\
62
+ "[:#{service.keys.join(', :')}]"
63
+ raise ServiceError.new(error)
64
+ end
65
+ service[operation]
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,75 @@
1
+ module Colppy
2
+ module Core
3
+ class Gateway
4
+ attr_reader :mode
5
+
6
+ MIME_JSON = "application/json".freeze
7
+ SANDBOX_API_URL = "http://staging.colppy.com".freeze
8
+ PRODUCTION_API_URL = "https://login.colppy.com".freeze
9
+ API_PATH = "/lib/frontera2/service.php".freeze
10
+
11
+ def initialize(mode = "sandbox")
12
+ @mode = mode
13
+ end
14
+
15
+ def call(payload = {})
16
+ make_request(payload)
17
+ end
18
+
19
+ def sandbox
20
+ @mode = "sandbox"
21
+ end
22
+
23
+ def sandbox?
24
+ @mode == "sandbox"
25
+ end
26
+
27
+ private
28
+
29
+ def headers
30
+ {
31
+ 'User-Agent' => "Colppy Ruby Gem v#{Colppy::VERSION}",
32
+ content_type: MIME_JSON,
33
+ accept: MIME_JSON
34
+ }
35
+ end
36
+
37
+ def make_request(payload)
38
+ unless payload.empty?
39
+ payload = MultiJson.dump(payload)
40
+ end
41
+ response = connection.post do |call|
42
+ call.url API_PATH
43
+ call.headers = headers
44
+ unless payload.empty?
45
+ call.body = payload
46
+ end
47
+ end
48
+
49
+ MultiJson.load(response.body, symbolize_keys: true)
50
+ rescue Exception => e
51
+ if e.respond_to?(:response)
52
+ MultiJson.load(e.response, symbolize_keys: true)
53
+ else
54
+ raise e
55
+ end
56
+ end
57
+
58
+ def connection
59
+ Faraday.new(endpoint_url) do |faraday|
60
+ faraday.adapter(Faraday.default_adapter)
61
+ end
62
+ end
63
+
64
+ def endpoint_url
65
+ case @mode
66
+ when "live" then PRODUCTION_API_URL
67
+ when "sandbox" then SANDBOX_API_URL
68
+ else
69
+ SANDBOX_API_URL
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end