firstgiving 1.0.0

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: 6a6851db81358b18da79f91eddc7d506c891ac2f
4
+ data.tar.gz: ebda58663a88fad10c5274b5633519c3aca1b132
5
+ SHA512:
6
+ metadata.gz: 4c66bc3913b0dcedc174fd58a6699f7263c029b5c1aa99da25fb3d4aae1568c2f9eb8fb00d47343c415253087caef84cfdffe1ac104716905dfd2443340ba4dd
7
+ data.tar.gz: 62d3afb72ee953eeba799b0584ffd8c6cea06d0b0c4ea6d6add7be675c4886a1ba2ef82ad17f84b9e53c71ddefb4ecb16bd6245e55b9217726219587247f4bbf
data/.gitignore ADDED
@@ -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
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format progress
3
+ --backtrace
4
+ --default_path spec
5
+ --pattern **/*.spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'coveralls', :require => false
4
+ # Specify your gem's dependencies in firstgiving.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Faizal Zakaria
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,52 @@
1
+ # FirstGiving
2
+
3
+ FirstGiving Ruby Client Open Source.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'firstgiving'
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install firstgiving
14
+
15
+ ## Usage
16
+
17
+
18
+ FirstGiving.configure do |config|
19
+ config.application_key = APPLICATION_KEY
20
+ config.security_token = SECURITY_TOKEN
21
+ config.options = OPTIONS
22
+ end
23
+
24
+ # Lookup API
25
+
26
+ FG.lookup.list(params)
27
+ FG.lookup.detail(params)
28
+
29
+ # Donation API
30
+
31
+ FG.donation.creditcard(params)
32
+ FG.donation.verify(params)
33
+ FG.donation.recurring_creditcard_profile(params)
34
+
35
+ # Search API
36
+
37
+ FG.search.query(params)
38
+
39
+
40
+
41
+ ## Test
42
+
43
+ rake spec
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'firstgiving/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "firstgiving"
8
+ spec.version = FirstGiving::VERSION
9
+ spec.authors = ["Faizal Zakaria"]
10
+ spec.email = ["phaibusiness@gmail.com"]
11
+ spec.description = %q{FirstGiving Ruby API client}
12
+ spec.summary = %q{FirstGiving API client}
13
+ spec.homepage = "https://github.com/boosterllc/firstgiving_ruby"
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
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "json"
25
+ spec.add_development_dependency "crack"
26
+ spec.add_development_dependency "faraday"
27
+ end
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'firstgiving/version'
3
+ require 'firstgiving/base'
4
+ require 'firstgiving/donation'
5
+ require 'firstgiving/lookup'
6
+ require 'firstgiving/search'
7
+
8
+ # Donation API
9
+ # Transaction API
10
+ # Search API
11
+
12
+ module FirstGiving
13
+
14
+ class Configuration
15
+ attr_accessor :application_key, :security_token, :options
16
+
17
+ def initialize
18
+ self.application_key = nil
19
+ self.security_token = nil
20
+ self.options = {}
21
+ set_defaults
22
+ end
23
+
24
+ def set_defaults
25
+ self.options[:verbose] ||= false
26
+ self.options[:read_timeout] ||= 30
27
+ self.options[:use_ssl] ||= false
28
+ self.options[:use_staging] ||= true
29
+ end
30
+ end
31
+
32
+ def self.configuration
33
+ @configuration ||= Configuration.new
34
+ end
35
+
36
+ def self.configure
37
+ yield(configuration) if block_given?
38
+ end
39
+
40
+ def self.lookup
41
+ @lookup ||= Lookup.new
42
+ end
43
+
44
+ def self.search
45
+ @search ||= Search.new
46
+ end
47
+
48
+ def self.donation
49
+ @donation ||= Donation.new
50
+ end
51
+
52
+ end
53
+
54
+ FG = FirstGiving
@@ -0,0 +1,57 @@
1
+ require 'faraday'
2
+
3
+ module FirstGiving
4
+
5
+ module Base
6
+
7
+ DONATION_SANDBOX_ENDPOINT = "http://usapisandbox.fgdev.net"
8
+ DONATION_PRODUCTION_ENDPOINT = "https://api.firstgiving.com"
9
+ SEARCH_ENDPOINT = "http://graphapi.firstgiving.com"
10
+
11
+ def headers_json
12
+ {
13
+ 'User-Agent' => 'FirstGiving Ruby SDK',
14
+ 'Content-Type' => 'application/json'
15
+ }
16
+ end
17
+
18
+ def headers_security
19
+ {
20
+ 'JG_APPLICATIONKEY' => "#{FirstGiving.configuration.application_key}",
21
+ 'JG_SECURITYTOKEN' => "#{FirstGiving.configuration.security_token}"
22
+ }
23
+ end
24
+
25
+ def post_call(api_endpoint, action, params, headers)
26
+ conn = Faraday.new(:url => api_endpoint) do |faraday|
27
+ faraday.request :url_encoded
28
+ faraday.adapter Faraday.default_adapter
29
+ end
30
+
31
+ response = conn.post do |req|
32
+ req.url action
33
+ req.params = params
34
+ req.headers = headers
35
+ end
36
+ end
37
+
38
+ def get_call(api_endpoint, action, params, headers)
39
+ conn = Faraday.new(:url => api_endpoint) do |faraday|
40
+ faraday.request :url_encoded # form-encode POST params
41
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
42
+ end
43
+
44
+ response = conn.get do |req|
45
+ req.url action
46
+ req.params = params
47
+ req.headers = headers
48
+ end
49
+ end
50
+
51
+ def logging(msg)
52
+ puts "[FG-LOG] #{msg}" if FirstGiving.configuration.options[:verbose]
53
+ end
54
+
55
+ end
56
+ end
57
+
@@ -0,0 +1,44 @@
1
+ require 'crack'
2
+
3
+ module FirstGiving
4
+
5
+ class Donation
6
+
7
+ include Base
8
+
9
+ module Actions
10
+ CREDITCARD = "/donation/creditcard"
11
+ RECURRING_CREDITCARD_PROFILE = "/donation/recurringcreditcardprofile"
12
+ VERIFY = "/verify"
13
+ end
14
+
15
+ def initialize
16
+ @api_endpoint = DONATION_PRODUCTION_ENDPOINT
17
+ @api_endpoint = DONATION_SANDBOX_ENDPOINT if FirstGiving.configuration.options[:use_staging]
18
+ end
19
+
20
+ def headers
21
+ headers_json.merge!(headers_security)
22
+ end
23
+
24
+ def creditcard(params)
25
+ response = post_call(@api_endpoint, Actions::CREDITCARD, params, headers)
26
+ parse(response.body)
27
+ end
28
+
29
+ def verify(params)
30
+ response = get_call(@api_endpoint, Actions::VERIFY, params, headers)
31
+ parse(response.body)
32
+ end
33
+
34
+ def recurring_creditcard_profile(params)
35
+ call(Actions::RECURRING_CREDITCARD_PROFILE, params, headers)
36
+ end
37
+
38
+ def parse(body)
39
+ Crack::XML.parse(body)
40
+ end
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,42 @@
1
+ require 'crack'
2
+ # lookup API
3
+
4
+ module FirstGiving
5
+
6
+ class Lookup
7
+
8
+ include Base
9
+
10
+ module Actions
11
+ TRANSACTION_LIST = "/transaction/list"
12
+ TRANSACTION_DETAIL = "/transaction/detail"
13
+ end
14
+
15
+ def initialize
16
+ @api_endpoint = DONATION_PRODUCTION_ENDPOINT
17
+ @api_endpoint = DONATION_SANDBOX_ENDPOINT if FirstGiving.configuration.options[:use_staging]
18
+ end
19
+
20
+ def headers
21
+ headers_json.merge!(headers_security)
22
+ end
23
+
24
+ def call(action, params, _headers)
25
+ response = get_call(@api_endpoint, action, params, _headers)
26
+ parse(response.body)
27
+ end
28
+
29
+ def detail(params)
30
+ call(Actions::TRANSACTION_DETAIL, params, headers)
31
+ end
32
+
33
+ def list(params)
34
+ call(Actions::TRANSACTION_LIST, params, headers)
35
+ end
36
+
37
+ def parse(body)
38
+ Crack::XML.parse(body)
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+
3
+ # Search API
4
+
5
+ module FirstGiving
6
+
7
+ class Search
8
+
9
+ include Base
10
+
11
+ module Actions
12
+ LIST_ORGANIZATION = "/v1/list/organization"
13
+ end
14
+
15
+ def initialize
16
+ @api_endpoint = SEARCH_ENDPOINT
17
+ end
18
+
19
+ def headers
20
+ {'Accept' => 'application/json'}
21
+ end
22
+
23
+ def query(params)
24
+ response = get_call(@api_endpoint, Actions::LIST_ORGANIZATION, params, headers)
25
+ parse(response.body)
26
+ end
27
+
28
+ def parse(body)
29
+ response = JSON.parse(body)
30
+ response['payload']
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module FirstGiving
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe FirstGiving do
4
+
5
+ APPLICATION_KEY = "ADD YOUR APP KEY HERE"
6
+ SECURITY_TOKEN = "ADD YOUR SECURITY TOKEN HERE"
7
+
8
+ OPTIONS = {
9
+ :use_staging => true
10
+ }
11
+
12
+ FirstGiving.configure do |config|
13
+ config.application_key = APPLICATION_KEY
14
+ config.security_token = SECURITY_TOKEN
15
+ config.options = OPTIONS
16
+ end
17
+
18
+ @transacionId = "a-a8ca75adcda6874abd9c5b"
19
+
20
+ describe "Test Donation API" do
21
+
22
+ it "should donate" do
23
+ params = {
24
+ :ccNumber => "4457010000000009",
25
+ :ccType => "VI",
26
+ :ccExpDateMonth => "01",
27
+ :ccExpDateYear => "14",
28
+ :billToAddressLine1 => "1 Main St.",
29
+ :billToCity => "Burlington",
30
+ :billToState => "MA",
31
+ :billToZip => "01803",
32
+ :remoteAddr => "120.138.91.2",
33
+ :amount => "10.00",
34
+ :currencyCode => "USD",
35
+ :charityId => "1234",
36
+ :description => "Test transaction",
37
+ :ccCardValidationNum => "349",
38
+ :billToFirstName => "Smith",
39
+ :billToLastName => "John",
40
+ :billToCountry => "US",
41
+ :billToEmail => "test@example.com"
42
+ }
43
+
44
+ response = FG.donation.creditcard(params)
45
+ ## Response should success
46
+ assert_acknowledgement(response)
47
+ ## Response should contain transaction ID
48
+ @transactionId = response["firstGivingDonationApi"]["firstGivingResponse"]["transactionId"]
49
+ @transactionId.should_not be_nil
50
+ end
51
+
52
+ it "should verify" do
53
+ params = {
54
+ :message => "value1",
55
+ :signature => "value2"
56
+ }
57
+
58
+ response = FG.donation.verify(params)
59
+ ## Response should return the same message and signature
60
+ response["firstGivingDonationApi"]["firstGivingResponse"]["signature"] == "value2"
61
+ response["firstGivingDonationApi"]["firstGivingResponse"]["message"] == "value1"
62
+ end
63
+
64
+ it "shoould recure the payment" do
65
+ end
66
+
67
+ end
68
+
69
+ describe "Test Lookup API" do
70
+
71
+ it "should return a list of transactions" do
72
+ params = {
73
+ page_size: 10,
74
+ date_from: "1388707200",
75
+ count: 100,
76
+ page: 1
77
+ }
78
+ resp = FG.lookup.list(params)
79
+ assert_acknowledgement(resp)
80
+ end
81
+
82
+ it "should return a transaction detail" do
83
+ params = {
84
+ transactionId: "a-0070dde28ca48048a1fc24"
85
+ }
86
+ resp = FG.lookup.detail(params)
87
+ assert_acknowledgement(resp)
88
+ end
89
+
90
+ end
91
+
92
+ context "Test Search API" do
93
+
94
+ describe "retrieving a charity by EIN" do
95
+ it "should return data for charities" do
96
+ params = {
97
+ q: "government_id:260046127"
98
+ }
99
+
100
+ response = FG.search.query(params)
101
+ response.should_not be_nil
102
+ response[0]["government_id"].should eq "260046127"
103
+ end
104
+ end
105
+
106
+ describe "searching for records by organization name" do
107
+ it "exact name matching and partial or name start" do
108
+ params = {
109
+ q: "organization_name:humane society"
110
+ }
111
+
112
+ response = FG.search.query(params)
113
+ response.should_not be_nil
114
+ response[0]["organization_name"].should include "HUMANE SOCIETY"
115
+ end
116
+
117
+ it "country constraints" do
118
+ params = {
119
+ q: "organization_name:bat AND country:US"
120
+ }
121
+
122
+ response = FG.search.query(params)
123
+ response.should_not be_nil
124
+ response[0]["organization_name"].should include "BAT"
125
+ response[0]["country"].should eq "US"
126
+ end
127
+
128
+ it "pagination" do
129
+ params = {
130
+ q: "organization_name:bat AND country:US",
131
+ page_size: "10",
132
+ page: 1
133
+ }
134
+
135
+ response = FG.search.query(params)
136
+ response.should_not be_nil
137
+ response[0]["organization_name"].should include "BAT"
138
+ response[0]["country"].should eq "US"
139
+ response.count.should eq 10
140
+ end
141
+ end
142
+ end
143
+
144
+ private
145
+
146
+ def assert_acknowledgement(response)
147
+ response["firstGivingDonationApi"]["firstGivingResponse"]["acknowledgement"].should eq "Success"
148
+ end
149
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'firstgiving'
3
+ require 'coveralls'
4
+ require 'faraday'
5
+ Coveralls.wear!
6
+
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firstgiving
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Faizal Zakaria
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-17 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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: crack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: FirstGiving Ruby API client
98
+ email:
99
+ - phaibusiness@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - firstgiving.gemspec
111
+ - lib/firstgiving.rb
112
+ - lib/firstgiving/base.rb
113
+ - lib/firstgiving/donation.rb
114
+ - lib/firstgiving/lookup.rb
115
+ - lib/firstgiving/search.rb
116
+ - lib/firstgiving/version.rb
117
+ - spec/first_giving_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/boosterllc/firstgiving_ruby
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.1.11
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: FirstGiving API client
143
+ test_files:
144
+ - spec/first_giving_spec.rb
145
+ - spec/spec_helper.rb