crowd_pay 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bec0fcfed8fb23b0a04b48bae47c2c0e39e64fb9
4
+ data.tar.gz: 4ed397b249ac5af256c3d0445ebd2e9867136e8b
5
+ SHA512:
6
+ metadata.gz: 6c66abf20d3d9f0a6bf57526d5fd42552bc69944b628182468a745682fa76386fb0211845404147a0ea4e982097c49ed8c28ecefc4aaa60a6b3310ed8013948b
7
+ data.tar.gz: c343df99d5447d4e0325a9a3c15721819685bf57923a34e66120d2f6bcb883d3746a93600c4a8f7c9cfe02f9ffc7b9a8df119d7a43cd5ac02a330e9bf0d922ac
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ bundler_args: --without development
5
+ rvm:
6
+ - ruby-head
7
+ - ruby
8
+ - 2.2.0
9
+ - 2.1.0
10
+ - 2.0.0
11
+ - 1.9.3
12
+ - jruby-head
13
+ - jruby
14
+ - jruby-19mode
15
+ - rbx-head
16
+ - rbx-2
17
+ matrix:
18
+ fast_finish: true
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+ - rvm: ruby
22
+ - rvm: jruby-head
23
+ - rvm: jruby
24
+ - rvm: rbx-head
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'webmock'
9
+ gem 'factory_girl'
10
+ gem 'codeclimate-test-reporter', require: nil
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ crowd_pay (0.0.1)
5
+ activemodel
6
+ faraday (~> 0.9)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (4.2.6)
12
+ activesupport (= 4.2.6)
13
+ builder (~> 3.1)
14
+ activesupport (4.2.6)
15
+ i18n (~> 0.7)
16
+ json (~> 1.7, >= 1.7.7)
17
+ minitest (~> 5.1)
18
+ thread_safe (~> 0.3, >= 0.3.4)
19
+ tzinfo (~> 1.1)
20
+ addressable (2.4.0)
21
+ builder (3.2.2)
22
+ codeclimate-test-reporter (0.5.0)
23
+ simplecov (>= 0.7.1, < 1.0.0)
24
+ crack (0.4.3)
25
+ safe_yaml (~> 1.0.0)
26
+ diff-lcs (1.2.5)
27
+ docile (1.1.5)
28
+ factory_girl (4.2.0)
29
+ activesupport (>= 3.0.0)
30
+ faraday (0.9.2)
31
+ multipart-post (>= 1.2, < 3)
32
+ hashdiff (0.3.0)
33
+ i18n (0.7.0)
34
+ json (1.8.3)
35
+ minitest (5.8.4)
36
+ multipart-post (2.0.0)
37
+ rake (10.4.2)
38
+ rspec (2.14.1)
39
+ rspec-core (~> 2.14.0)
40
+ rspec-expectations (~> 2.14.0)
41
+ rspec-mocks (~> 2.14.0)
42
+ rspec-core (2.14.8)
43
+ rspec-expectations (2.14.5)
44
+ diff-lcs (>= 1.1.3, < 2.0)
45
+ rspec-mocks (2.14.6)
46
+ safe_yaml (1.0.4)
47
+ simplecov (0.11.2)
48
+ docile (~> 1.1.0)
49
+ json (~> 1.8)
50
+ simplecov-html (~> 0.10.0)
51
+ simplecov-html (0.10.0)
52
+ thread_safe (0.3.5)
53
+ tzinfo (1.2.2)
54
+ thread_safe (~> 0.1)
55
+ webmock (1.24.2)
56
+ addressable (>= 2.3.6)
57
+ crack (>= 0.3.2)
58
+ hashdiff
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ codeclimate-test-reporter
65
+ crowd_pay!
66
+ factory_girl
67
+ rake
68
+ rspec
69
+ webmock
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Qwinix Technologies
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # CrowdPay
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/qwinix%2Fcrowd_pay.svg)](https://badge.fury.io/rb/qwinix%2Fcrowd_pay)
4
+ [![Build Status](https://travis-ci.org/Qwinix/crowd_pay.svg?branch=master)](https://travis-ci.org/Qwinix/crowd_pay)
5
+ [![Dependency Status](https://gemnasium.com/Qwinix/crowd_pay.svg)](https://gemnasium.com/Qwinix/crowd_pay)
6
+ [![Test Coverage](https://codeclimate.com/github/Qwinix/crowd_pay/badges/coverage.svg)](https://codeclimate.com/github/Qwinix/crowd_pay/coverage)
7
+ [![Code Climate](https://codeclimate.com/github/Qwinix/crowd_pay/badges/gpa.svg)](https://codeclimate.com/github/Qwinix/crowd_pay)
8
+
9
+
10
+ A ruby client for [CrowdPay's API](//crowdpay.com/api-documentation) using ActiveRecord for easy to use ruby objects.
11
+
12
+ This gem has been extracted from the [Vested.org](//vested.org) project courtesy of [Calvert Foundation](calvertfoundation.org).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task default: [:spec]
4
+
5
+ task :spec do
6
+ sh 'bundle exec rspec spec'
7
+ end
data/crowd_pay.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../lib/crowd_pay/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'crowd_pay'
5
+ gem.version = CrowdPay::VERSION
6
+ gem.date = '2016-02-23'
7
+ gem.summary =
8
+ gem.description = 'CrowdPay.com API wrapper for Ruby'
9
+ gem.authors = ['Kelton Manzanares', 'Prakash Lingaiah', 'Krishnaprasad Varma']
10
+ gem.email = ['kelton.manzanares@gmail.com', 'plingaiah@qwinix.io', 'kvarma@qwinix.io']
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.homepage = 'https://github.com/qwinix/crowd_pay'
13
+ gem.license = 'MIT'
14
+
15
+ gem.add_runtime_dependency 'activemodel'
16
+ gem.add_runtime_dependency 'faraday', '~> 0.9'
17
+ end
data/lib/crowd_pay.rb ADDED
@@ -0,0 +1,163 @@
1
+ require 'active_model'
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'crowd_pay/version'
5
+
6
+ module CrowdPay
7
+ autoload :Account, 'crowd_pay/account'
8
+ autoload :Asset, 'crowd_pay/asset'
9
+ autoload :Escrow, 'crowd_pay/escrow'
10
+ autoload :Investor, 'crowd_pay/investor'
11
+ autoload :Transaction, 'crowd_pay/transaction'
12
+ autoload :Verification, 'crowd_pay/verification'
13
+
14
+ module InstanceMethods
15
+ def initialize(opts={})
16
+ opts.each do |k, v|
17
+ associations = self.class.class_variable_get(:@@associations)
18
+ assoc_name = k.downcase.to_sym
19
+
20
+ if associations.has_key?(assoc_name)
21
+ klass = associations[assoc_name][:class_name].constantize
22
+
23
+ association = v.each_with_object([]) do |data, array|
24
+ obj = klass.new
25
+ obj.assign_attributes(data)
26
+ array << obj
27
+ end
28
+
29
+ instance_variable_set("@#{k.downcase}", association)
30
+ else
31
+ instance_variable_set("@#{k}", v)
32
+ end
33
+ end
34
+ end
35
+
36
+ def assign_attributes(hash)
37
+ self.send :initialize, hash
38
+ end
39
+
40
+ def populate_errors error
41
+ self.errors.add(:api, (error.has_key?("Message") ? error["Message"] : error))
42
+ if error.has_key?("ModelState")
43
+ model_state = error["ModelState"].symbolize_keys!
44
+ model_state.each do |k, v|
45
+ next if k == self.class.name.downcase.to_sym
46
+ v.each do |e|
47
+ self.errors.add(k.to_s.split(".").last, e)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ module ClassMethods
55
+ def create_connection
56
+ @@connection = Faraday.new(:url => domain) do |faraday|
57
+ # faraday.response :logger if Rails.env.develop? || Rails.env.test? # log requests to STDOUT
58
+ faraday.adapter Faraday.default_adapter
59
+
60
+ faraday.headers['X-ApiKey'] = api_key
61
+ faraday.headers['X-PortalKey'] = portal_key
62
+ faraday.headers['X-ByPassValidation'] = by_pass_validation if by_pass_validation
63
+ end
64
+ end
65
+
66
+ def parse(response)
67
+ body = JSON.parse response.body
68
+
69
+ if body.is_a? Hash
70
+ build_object response.status, body
71
+ else
72
+ body.map do |attributes|
73
+ build_object response.status, attributes
74
+ end
75
+ end
76
+ end
77
+
78
+ def build_object status, attributes
79
+ obj = self.new
80
+ case status
81
+ when 200, 201
82
+ build_hash_object obj, attributes
83
+ when 409
84
+ build_hash_object obj, attributes['ModelObject']
85
+ when 400, 405, 404
86
+ #FIX ME: 404 catching is not tested
87
+ obj.populate_errors attributes
88
+ else
89
+ obj.errors.add(:base, "Unknown Error Status #{status}: crowd_pay.rb#parse method")
90
+ end
91
+ return obj
92
+ end
93
+
94
+ def build_hash_object obj, attributes
95
+ attributes = attributes.each_with_object({}) do |(k, v), hash|
96
+ hash[k.downcase] = v
97
+ end
98
+ obj.assign_attributes(attributes)
99
+ end
100
+
101
+ def get(url)
102
+ connection.get do |req|
103
+ req.url(url)
104
+ req.headers['Content-Type'] = 'application/json'
105
+ end
106
+ end
107
+
108
+ def post(url, data, cip_by_pass_validation=false)
109
+ data = data.to_json unless data.kind_of? String
110
+
111
+ connection.post do |req|
112
+ req.url(url)
113
+ req.headers['Content-Type'] = 'application/json'
114
+ req.headers['X-CipByPassValidation'] = 'true' if cip_by_pass_validation
115
+ req.body = data
116
+ end
117
+ end
118
+
119
+ def put(url, data)
120
+ data = data.to_json unless data.kind_of? String
121
+
122
+ connection.put do |req|
123
+ req.url(url)
124
+ req.headers['Content-Type'] = 'application/json'
125
+ req.body = data
126
+ end
127
+ end
128
+
129
+ def delete(url)
130
+ connection.delete do |req|
131
+ req.url(url)
132
+ req.headers['Content-Type'] = 'application/json'
133
+ end
134
+ end
135
+
136
+ private
137
+
138
+ def register_association(assoc_name, details)
139
+ hash = class_variable_get(:@@associations)
140
+ class_variable_set(:@@associations, hash.merge({assoc_name => details.symbolize_keys}.symbolize_keys))
141
+ attr_accessor assoc_name.to_sym
142
+ end
143
+ end
144
+
145
+ def self.included(base)
146
+ base.send :include, InstanceMethods
147
+ base.extend ClassMethods
148
+ base.class_eval do
149
+ cattr_reader :domain, :api_key, :portal_key, :connection, :associations, :by_pass_validation
150
+
151
+ class_variable_set :@@domain, ENV['CROWD_PAY_DOMAIN']
152
+ class_variable_set :@@api_key, ENV['CROWD_PAY_API_KEY']
153
+ class_variable_set :@@portal_key, ENV['CROWD_PAY_PORTAL_KEY']
154
+ class_variable_set :@@by_pass_validation, ENV['CROWD_PAY_BY_PASS']
155
+ class_variable_set :@@associations, {}
156
+
157
+ unless(base.class_variable_get(:@@connection))
158
+ connection = base.create_connection
159
+ base.class_variable_set(:@@connection, connection)
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,83 @@
1
+ module CrowdPay
2
+ class Account
3
+ include ActiveModel::AttributeMethods
4
+ include ActiveModel::Validations
5
+ include CrowdPay
6
+
7
+ attr_accessor :id, :number, :portal_account_number, :investor_id,
8
+ :name_1, :name_2, :name_3, :name_4,
9
+ :mailing_address_1, :mailing_address_2, :mailing_city,
10
+ :mailing_state, :mailing_zip, :mailing_country,
11
+ :is_mailing_address_foreign, :is_cip_satisfied,
12
+ :draft_account_type_id, :draft_routing_number,
13
+ :draft_account_number, :draft_account_name, :status_id,
14
+ :account_type_id, :w9_code_id, :contact_name, :contact_phone,
15
+ :contact_email, :idology_id, :available_balance,
16
+ :current_balance, :created_by_ip_address
17
+
18
+
19
+
20
+ register_association :assets, class_name: "CrowdPay::Asset"
21
+ register_association :transactions, class_name: "CrowdPay::Transaction"
22
+
23
+ validates_presence_of :investor_id
24
+ validates_presence_of :status_id
25
+ validates_presence_of :account_type_id
26
+ validates_presence_of :is_mailing_address_foreign
27
+ validates_presence_of :is_cip_satisfied
28
+ validates_presence_of :draft_account_type_id
29
+ validates_presence_of :draft_routing_number
30
+ validates_presence_of :draft_account_number
31
+ validates_presence_of :draft_account_name
32
+ validates_presence_of :created_by_ip_address
33
+ validates_presence_of :w9_code_id
34
+ validates_length_of :portal_account_number, :maximum => 30
35
+ validates_length_of :name_1, :maximum => 50
36
+ validates_length_of :name_2, :maximum => 50
37
+ validates_length_of :name_3, :maximum => 50
38
+ validates_length_of :name_4, :maximum => 50
39
+ validates_length_of :mailing_address_1, :maximum => 40
40
+ validates_length_of :mailing_address_2, :maximum => 40
41
+ validates_length_of :mailing_city, :maximum => 40
42
+ validates_length_of :mailing_state, :maximum => 30
43
+ validates_length_of :mailing_zip, :maximum => 9
44
+ validates_length_of :mailing_country, :maximum => 40
45
+ validates_length_of :draft_routing_number, :maximum => 9
46
+ validates_length_of :draft_account_number, :maximum => 17
47
+ validates_length_of :draft_account_name, :maximum => 50
48
+ validates_length_of :contact_name, :maximum => 75
49
+ validates_length_of :contact_phone, :maximum => 20
50
+ validates_length_of :contact_email, :maximum => 50
51
+ validates_length_of :created_by_ip_address, :maximum => 25
52
+
53
+ def self.find(id)
54
+ url = "Crowdfunding/api/Account/#{id}"
55
+ response = get(url)
56
+ parse(response)
57
+ end
58
+
59
+ def self.find_with_transactions(id)
60
+ url = "Crowdfunding/api/Account/#{id}/Transaction"
61
+ response = get(url)
62
+ parse(response)
63
+ end
64
+
65
+ def self.create(data)
66
+ url = "Crowdfunding/api/Account"
67
+ response = post(url, data)
68
+ parse(response)
69
+ end
70
+
71
+ def self.update(id, data)
72
+ url = "Crowdfunding/api/Account/#{id}"
73
+ response = put(url, data)
74
+ parse(response)
75
+ end
76
+
77
+ def self.find_with_assets(account_id)
78
+ url = "Crowdfunding/api/V2/Account/#{account_id}/Assets/All"
79
+ response = get(url)
80
+ parse(response)
81
+ end
82
+ end
83
+ end