ammado 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +20 -0
- data/README.md +179 -0
- data/Rakefile +51 -0
- data/ammado.gemspec +73 -0
- data/lib/ammado/api.rb +70 -0
- data/lib/ammado/api_error.rb +57 -0
- data/lib/ammado/api_resource.rb +54 -0
- data/lib/ammado/categories.rb +12 -0
- data/lib/ammado/fundraiser.rb +27 -0
- data/lib/ammado/fundraiser_avatar.rb +33 -0
- data/lib/ammado/fundraiser_cover.rb +33 -0
- data/lib/ammado/fundraiser_moderator.rb +23 -0
- data/lib/ammado/search.rb +12 -0
- data/lib/ammado.rb +20 -0
- data/test/helper.rb +34 -0
- data/test/test_ammado.rb +7 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 61bb466c922e75ce5418280a3e782f5c06b31453
|
4
|
+
data.tar.gz: 31a082d883a4a0fcb424d9ef8a0169b49e0d3705
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e8529dbed9dd139e5addf39c0d8fed1fd3e0b76e4a092ebb8962d4c14111d5d1b48f480cdbfc116367aefac0b6d2fe39ab9475f06549fd7cfc3552c68de0f06
|
7
|
+
data.tar.gz: 93dd523f14fbbfd65d33ba6491f8355615790830342222627b4103d3ab31f0938909660ea3dd6b9763449fa8f922c77e19e4946c253970e3390e7baf1b97e99d
|
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.2.5)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.4.0)
|
11
|
+
builder (3.2.2)
|
12
|
+
descendants_tracker (0.0.4)
|
13
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
14
|
+
docile (1.1.5)
|
15
|
+
faraday (0.9.2)
|
16
|
+
multipart-post (>= 1.2, < 3)
|
17
|
+
git (1.2.9.1)
|
18
|
+
github_api (0.13.1)
|
19
|
+
addressable (~> 2.4.0)
|
20
|
+
descendants_tracker (~> 0.0.4)
|
21
|
+
faraday (~> 0.8, < 0.10)
|
22
|
+
hashie (>= 3.4)
|
23
|
+
multi_json (>= 1.7.5, < 2.0)
|
24
|
+
oauth2
|
25
|
+
hashie (3.4.3)
|
26
|
+
highline (1.7.8)
|
27
|
+
i18n (0.7.0)
|
28
|
+
jeweler (2.0.1)
|
29
|
+
builder
|
30
|
+
bundler (>= 1.0)
|
31
|
+
git (>= 1.2.5)
|
32
|
+
github_api
|
33
|
+
highline (>= 1.6.15)
|
34
|
+
nokogiri (>= 1.5.10)
|
35
|
+
rake
|
36
|
+
rdoc
|
37
|
+
json (1.8.3)
|
38
|
+
jwt (1.5.2)
|
39
|
+
mini_portile2 (2.0.0)
|
40
|
+
minitest (5.8.3)
|
41
|
+
multi_json (1.11.2)
|
42
|
+
multi_xml (0.5.5)
|
43
|
+
multipart-post (2.0.0)
|
44
|
+
nokogiri (1.6.7.1)
|
45
|
+
mini_portile2 (~> 2.0.0.rc2)
|
46
|
+
oauth2 (1.0.0)
|
47
|
+
faraday (>= 0.8, < 0.10)
|
48
|
+
jwt (~> 1.0)
|
49
|
+
multi_json (~> 1.3)
|
50
|
+
multi_xml (~> 0.5)
|
51
|
+
rack (~> 1.2)
|
52
|
+
rack (1.6.4)
|
53
|
+
rake (10.5.0)
|
54
|
+
rdoc (3.12.2)
|
55
|
+
json (~> 1.4)
|
56
|
+
shoulda (3.5.0)
|
57
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
58
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
59
|
+
shoulda-context (1.2.1)
|
60
|
+
shoulda-matchers (2.8.0)
|
61
|
+
activesupport (>= 3.0.0)
|
62
|
+
simplecov (0.11.1)
|
63
|
+
docile (~> 1.1.0)
|
64
|
+
json (~> 1.8)
|
65
|
+
simplecov-html (~> 0.10.0)
|
66
|
+
simplecov-html (0.10.0)
|
67
|
+
thread_safe (0.3.5)
|
68
|
+
tzinfo (1.2.2)
|
69
|
+
thread_safe (~> 0.1)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
bundler (~> 1.0)
|
76
|
+
jeweler (~> 2.0.1)
|
77
|
+
multipart-post
|
78
|
+
rdoc (~> 3.12)
|
79
|
+
shoulda
|
80
|
+
simplecov
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
1.11.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Margus Pärt
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
AMMADO API FOR RUBY (AND RAILS)
|
2
|
+
===============================
|
3
|
+
|
4
|
+
Contribution
|
5
|
+
------------
|
6
|
+
|
7
|
+
Please help to make this GEM better
|
8
|
+
+ by creating a Issue and then Pull Request with a fix to this Issue.
|
9
|
+
+ support its improvement with a donation.
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
Ammado API reference
|
14
|
+
--------------------
|
15
|
+
|
16
|
+
https://api.ammado.com/
|
17
|
+
|
18
|
+
|
19
|
+
Configuration
|
20
|
+
-------------
|
21
|
+
|
22
|
+
First define API link:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'ammado'
|
26
|
+
|
27
|
+
Ammado::Api.default_api_link = Ammado::Api.new(
|
28
|
+
key: "AMMADO_API_KEY_HERE",
|
29
|
+
secret: "AMMADO_API_KEY_HERE",
|
30
|
+
host: 'https://api.ammado.com/',
|
31
|
+
default_images_folder: '/folder/for/files/'
|
32
|
+
)
|
33
|
+
```
|
34
|
+
|
35
|
+
Note:
|
36
|
+
|
37
|
+
This configuration might have issues in threaded environments.
|
38
|
+
Simple fix would be defining only parameters, and when needed, creating a instance in ApiResource based on this configuration.
|
39
|
+
|
40
|
+
If issue exists see Contribution.
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
Implemented Endpoints and their usage
|
45
|
+
-------------------------------------
|
46
|
+
|
47
|
+
|
48
|
+
Note: you acn use parameter names both "beneficiary_id" and "beneficiaryId", but for better readibility and following Ruby standards,
|
49
|
+
I recommend under_scored, not camelCase.
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
### https://api.ammado.com/#FundraiserEndpoint
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
ammado_fundraiser = Ammado::Fundraiser.create(
|
57
|
+
beneficiary_id: '123',
|
58
|
+
fundraiser_title: 'Title',
|
59
|
+
fundraiser_description: 'Description',
|
60
|
+
target_amount: '10.00',
|
61
|
+
target_currency_code: 'EUR',
|
62
|
+
thank_you_message: 'Thank you for the donation.'
|
63
|
+
)
|
64
|
+
|
65
|
+
if ammado_fundraiser.created?
|
66
|
+
puts "Created a fundraiser, with permalink: #{ ammado_fundraiser.permalink }"
|
67
|
+
else
|
68
|
+
puts "Failed to create fundraiser and got errors"
|
69
|
+
puts ammando_fundraiser.errors.map(&:message).join(', ')
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "All params for fundraiser are: #{ ammado_fundraiser.params.inspect }"
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
### https://api.ammado.com/#FundraiserModeratorEndpoint
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
fundraiser_id = ammado_fundraiser.permalink.split('/').last
|
81
|
+
|
82
|
+
ammado_fundraiser_moderator = Ammado::FundraiserModerator.create(
|
83
|
+
fundraiser_id: fundraiser_id,
|
84
|
+
first_name: name,
|
85
|
+
last_name: lastname,
|
86
|
+
email: email
|
87
|
+
)
|
88
|
+
|
89
|
+
if ammado_fundraiser_moderator.created?
|
90
|
+
puts "Created a moderator, with params: #{ ammado_fundraiser_moderator.params.inspect }"
|
91
|
+
else
|
92
|
+
puts "Failed to create fundraiser and got errors"
|
93
|
+
puts ammando_fundraiser.errors.map(&:message).join(', ')
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
### https://api.ammado.com/#FundraiserModeratorEndpoint
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
fundraiser_id = ammado_fundraiser.permalink.split('/').last
|
103
|
+
|
104
|
+
ammado_fundraiser_moderator = Ammado::FundraiserModerator.create(
|
105
|
+
fundraiser_id: fundraiser_id,
|
106
|
+
first_name: name,
|
107
|
+
last_name: lastname,
|
108
|
+
email: email
|
109
|
+
)
|
110
|
+
|
111
|
+
if ammado_fundraiser_moderator.created?
|
112
|
+
puts "Created a moderator, with params: #{ ammado_fundraiser_moderator.params.inspect }"
|
113
|
+
else
|
114
|
+
puts "Failed to create fundraiser and got errors"
|
115
|
+
puts ammando_fundraiser.errors.map(&:message).join(', ')
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
### https://api.ammado.com/#FundraiserAvatarEndpoint
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
fundraiser_id = ammado_fundraiser.permalink.split('/').last
|
125
|
+
|
126
|
+
ammado_fundraiser_avatar = Ammado::FundraiserAvatar.create(
|
127
|
+
fundraiser_id: fundraiser_id,
|
128
|
+
file_name: 'fundraiser_avatar.png'
|
129
|
+
)
|
130
|
+
|
131
|
+
if ammado_fundraiser_avatar.created?
|
132
|
+
puts "Created a moderator, with params: #{ ammado_fundraiser_avatar.params.inspect }"
|
133
|
+
else
|
134
|
+
puts "Failed to create fundraiser and got errors"
|
135
|
+
puts ammado_fundraiser_avatar.errors.map(&:message).join(', ')
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
### https://api.ammado.com/#FundraiserCoverEndpoint
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
fundraiser_id = ammado_fundraiser.permalink.split('/').last
|
145
|
+
|
146
|
+
ammado_fundraiser_cover = Ammado::FundraiserCover.create(
|
147
|
+
fundraiser_id: fundraiser_id,
|
148
|
+
file_name: 'fundraiser_cover.png'
|
149
|
+
)
|
150
|
+
|
151
|
+
if ammado_fundraiser_cover.created?
|
152
|
+
puts "Created a moderator, with params: #{ ammado_fundraiser_cover.params.inspect }"
|
153
|
+
else
|
154
|
+
puts "Failed to create fundraiser and got errors: "
|
155
|
+
puts ammado_fundraiser_cover.errors.map(&:message).join(', ')
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
|
160
|
+
### https://api.ammado.com/#CategoriesEndpoint
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
categories = Ammado::Categories.all
|
164
|
+
```
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
### https://api.ammado.com/#SearchEndpoint
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
found = Ammado::Search.where(search_params)
|
172
|
+
```
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
Author
|
177
|
+
------
|
178
|
+
|
179
|
+
Margus Pärt (http://wave.ee)
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "ammado"
|
18
|
+
gem.homepage = "http://github.com/mxrguspxrt/ammado"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{TODO: one-line summary of your gem}
|
21
|
+
gem.description = %Q{TODO: longer description of your gem}
|
22
|
+
gem.email = "margus@wave.ee"
|
23
|
+
gem.authors = ["Margus Pxrt"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "ammado #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/ammado.gemspec
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "ammado"
|
8
|
+
s.version = "1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Margus Pxrt"]
|
12
|
+
s.date = "2016-01-20"
|
13
|
+
s.description = "Using Ammado API with Ruby (and Rails). https://api.ammado.com/"
|
14
|
+
s.email = "margus@wave.ee"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"ammado.gemspec",
|
27
|
+
"lib/ammado.rb",
|
28
|
+
"lib/ammado/api.rb",
|
29
|
+
"lib/ammado/api_error.rb",
|
30
|
+
"lib/ammado/api_resource.rb",
|
31
|
+
"lib/ammado/categories.rb",
|
32
|
+
"lib/ammado/fundraiser.rb",
|
33
|
+
"lib/ammado/fundraiser_avatar.rb",
|
34
|
+
"lib/ammado/fundraiser_cover.rb",
|
35
|
+
"lib/ammado/fundraiser_moderator.rb",
|
36
|
+
"lib/ammado/search.rb",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_ammado.rb"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/mxrguspxrt/ammado"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = "2.0.14"
|
44
|
+
s.summary = "Using Ammado API with Ruby (and Rails). https://api.ammado.com/"
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 4
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
55
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<multipart-post>, [">= 0"])
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
62
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<multipart-post>, [">= 0"])
|
66
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
70
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/lib/ammado/api.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'net/http/post/multipart'
|
2
|
+
|
3
|
+
module Ammado
|
4
|
+
|
5
|
+
class Api
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :default_api_link
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :key,
|
12
|
+
:secret,
|
13
|
+
:host,
|
14
|
+
:default_images_folder
|
15
|
+
|
16
|
+
def initialize(opts)
|
17
|
+
@key = opts[:key]
|
18
|
+
@secret = opts[:secret]
|
19
|
+
@host = opts[:host]
|
20
|
+
@default_images_folder = opts[:default_images_folder]
|
21
|
+
end
|
22
|
+
|
23
|
+
def post(endpoint, params)
|
24
|
+
log('Ammado POST')
|
25
|
+
log('Endpoint: ' + endpoint)
|
26
|
+
log('Params: ' + params.to_s)
|
27
|
+
|
28
|
+
uri = URI(@host + endpoint)
|
29
|
+
response = Net::HTTP.post_form(uri, params)
|
30
|
+
log('Got response: ' + response.body)
|
31
|
+
|
32
|
+
return [response.code, ActiveSupport::JSON.decode(response.body)]
|
33
|
+
end
|
34
|
+
|
35
|
+
def post_multipart(endpoint, params)
|
36
|
+
log('Ammado POST file')
|
37
|
+
log('Endpoint: ' + endpoint)
|
38
|
+
log('Params: ' + params.to_s)
|
39
|
+
|
40
|
+
uri = URI(@host + endpoint)
|
41
|
+
|
42
|
+
request = Net::HTTP::Post::Multipart.new(uri.path, params)
|
43
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
44
|
+
http.request(request)
|
45
|
+
end
|
46
|
+
|
47
|
+
log('Got response: ' + response.body)
|
48
|
+
return [response.code, ActiveSupport::JSON.decode(response.body)]
|
49
|
+
end
|
50
|
+
|
51
|
+
def get(endpoint, params)
|
52
|
+
log('Ammado GET')
|
53
|
+
log('Endpoint: ' + endpoint)
|
54
|
+
log('Params: ' + params.to_s)
|
55
|
+
|
56
|
+
full_url = [@host + endpoint, URI.encode_www_form(params)].compact.join('?')
|
57
|
+
uri = URI(full_url)
|
58
|
+
response = Net::HTTP.get_response(uri)
|
59
|
+
log('Got response: ' + response.body)
|
60
|
+
|
61
|
+
return [response.code, ActiveSupport::JSON.decode(response.body)]
|
62
|
+
end
|
63
|
+
|
64
|
+
def log(message)
|
65
|
+
Rails.logger.info(message)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
AMMADO_ERRORS = {
|
2
|
+
'1101' => ['beneficiaryId', 'Beneficiary is invalid'],
|
3
|
+
'1102' => ['beneficiaryId', 'Beneficiary does not accept donations'],
|
4
|
+
'1105' => ['beneficiaryId', 'Limit reached'],
|
5
|
+
'1107' => ['beneficiaryId', 'Multiple beneficiaries from the same country'],
|
6
|
+
'1804' => ['fundraiserAim', 'Fundraiser aim is too long (max 200 characters)'],
|
7
|
+
'1801' => ['fundraiserDescription', 'Description field can have max 1000 characters'],
|
8
|
+
'1701' => ['fundraiserTitle', 'Please enter a title for your fundraiser'],
|
9
|
+
'1702' => ['fundraiserTitle', 'Name must be between 2 and 200 characters in length'],
|
10
|
+
'2101' => ['fundraiserType', 'Invalid fundraiser type'],
|
11
|
+
'2301' => ['isSearchable', 'Invalid parameter value'],
|
12
|
+
'2701' => ['partnerCode', 'Invalid parameter value'],
|
13
|
+
'1304' => ['targetAmount', 'Target amount must be a number'],
|
14
|
+
'1305' => ['targetAmount', 'The target amount must be greater'],
|
15
|
+
'1306' => ['targetAmount', 'The target amount must be smaller'],
|
16
|
+
'1201' => ['targetCurrencyCode', 'Unsupported currency'],
|
17
|
+
'1803' => ['thankYouMessage', 'Thank you message field can have max 1000 characters'],
|
18
|
+
'1901' => ['signature', 'Invalid signature'],
|
19
|
+
'1401' => ['email', 'You must provide a valid email addres'],
|
20
|
+
'1402' => ['email', 'Email address must be formatted correctly (for example jsmith@example.com)'],
|
21
|
+
'1403' => ['email', 'Email provided was too long (max 100 characters)'],
|
22
|
+
'1404' => ['email', 'Invite already sent'],
|
23
|
+
'1501' => ['firstName', 'Sorry, the first name you entered does not seem to be valid. Please enter a name between 1 and 100'],
|
24
|
+
'1502' => ['firstName', 'First name too long (max 100 characters)'],
|
25
|
+
'1601' => ['lastName', 'Sorry, the last name you entered does not seem to be valid. Please enter a name between 1 and 100 characters long. Some characters may not be valid'],
|
26
|
+
'1602' => ['lastName', 'Last name too long (max 100 characters)'],
|
27
|
+
'2801' => ['avatar', 'File upload failed'],
|
28
|
+
'2802' => ['avatar', 'File size is too big. Maximum allowed is 5MB'],
|
29
|
+
'2803' => ['avatar', 'File format is not valid. Accepted file types are: gif, png, bmp, jpeg, jpg'],
|
30
|
+
'2804' => ['avatar', 'File not found'],
|
31
|
+
'2801' => ['coverImage', 'File upload failed'],
|
32
|
+
'2802' => ['coverImage', 'File size is too big. Maximum allowed is 5MB'],
|
33
|
+
'2803' => ['coverImage', 'File format is not valid. Accepted file types are: gif, png, bmp, jpeg, jpg'],
|
34
|
+
'2804' => ['coverImage', 'File not found']
|
35
|
+
}
|
36
|
+
|
37
|
+
module Ammado
|
38
|
+
|
39
|
+
class ApiError
|
40
|
+
|
41
|
+
attr_reader :code
|
42
|
+
|
43
|
+
def initialize(code)
|
44
|
+
@code = code
|
45
|
+
end
|
46
|
+
|
47
|
+
def param_name
|
48
|
+
AMMADO_ERRORS[code.to_s][0]
|
49
|
+
end
|
50
|
+
|
51
|
+
def message
|
52
|
+
AMMADO_ERRORS[code.to_s][1]
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Ammado
|
2
|
+
|
3
|
+
class ApiResource
|
4
|
+
|
5
|
+
def self.create(params)
|
6
|
+
resource = new(params)
|
7
|
+
resource.create
|
8
|
+
return resource
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :params
|
12
|
+
|
13
|
+
def create
|
14
|
+
code, response = api.post(resource_create_path, params.merge(signature: calculate_signature, apiKey: api.key))
|
15
|
+
@params.merge!(response)
|
16
|
+
return code == '201'
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(params)
|
20
|
+
@params = {}
|
21
|
+
params.each do |k, v|
|
22
|
+
send("#{k}=", v)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(m, value=nil)
|
27
|
+
meth = m.to_s
|
28
|
+
if meth.last == '='
|
29
|
+
assign_meth = meth[0..-2]
|
30
|
+
params[assign_meth.underscore] = params[assign_meth.camelize(:lower)] = value
|
31
|
+
else
|
32
|
+
return params[meth.underscore] || params[meth.camelize(:lower)]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.api
|
37
|
+
Ammado::Api.default_api_link
|
38
|
+
end
|
39
|
+
|
40
|
+
def api
|
41
|
+
Ammado::Api.default_api_link
|
42
|
+
end
|
43
|
+
|
44
|
+
def errors
|
45
|
+
if error_codes
|
46
|
+
error_codes.map {|code| Ammado::ApiError.new(code) }
|
47
|
+
else
|
48
|
+
[]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ammado
|
2
|
+
|
3
|
+
# https://api.ammado.com/#FundraiserEndpoint
|
4
|
+
class Fundraiser < ApiResource
|
5
|
+
|
6
|
+
def resource_create_path
|
7
|
+
'/v1/fundraiser'
|
8
|
+
end
|
9
|
+
|
10
|
+
def created?
|
11
|
+
!!permalink
|
12
|
+
end
|
13
|
+
|
14
|
+
def calculate_signature
|
15
|
+
Rails.logger.info('Calculate signature for ' + @params.to_s)
|
16
|
+
signature_parts = []
|
17
|
+
signature_parts << beneficiary_id
|
18
|
+
signature_parts << Base64.strict_encode64(fundraiser_title)
|
19
|
+
signature_parts << api.secret
|
20
|
+
plain_signature = signature_parts.flatten.join('.')
|
21
|
+
Rails.logger.info('Plain signature is ' + plain_signature)
|
22
|
+
return Digest::SHA1.hexdigest(plain_signature).upcase
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ammado
|
2
|
+
|
3
|
+
# https://api.ammado.com/#FundraiserAvatarEndpoint
|
4
|
+
class FundraiserAvatar < ApiResource
|
5
|
+
|
6
|
+
def create
|
7
|
+
File.open(api.default_images_folder + file_name) do |file|
|
8
|
+
file_postfix = file_name.split('.').last
|
9
|
+
upload_io_file = UploadIO.new(file, AMMADO_FILE_POSTFIX_TO_TYPE[file_postfix], file_name)
|
10
|
+
code, response = api.post_multipart(resource_create_path, params.merge(avatar: upload_io_file, signature: calculate_signature, apiKey: api.key))
|
11
|
+
@params.merge!(response)
|
12
|
+
return code == '201'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource_create_path
|
17
|
+
"/v1/fundraiser/#{fundraiser_id}/avatar"
|
18
|
+
end
|
19
|
+
|
20
|
+
def calculate_signature
|
21
|
+
Rails.logger.info('Calculate signature for ' + @params.to_s)
|
22
|
+
signature_parts = []
|
23
|
+
signature_parts << fundraiser_id
|
24
|
+
signature_parts << Base64.strict_encode64(file_name)
|
25
|
+
signature_parts << api.secret
|
26
|
+
plain_signature = signature_parts.flatten.join('.')
|
27
|
+
Rails.logger.info('Plain signature is ' + plain_signature)
|
28
|
+
return Digest::SHA1.hexdigest(plain_signature).upcase
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Ammado
|
2
|
+
|
3
|
+
# https://api.ammado.com/#FundraiserCoverEndpoint
|
4
|
+
class FundraiserCover < ApiResource
|
5
|
+
|
6
|
+
def create
|
7
|
+
File.open(api.default_images_folder + file_name) do |file|
|
8
|
+
file_postfix = file_name.split('.').last
|
9
|
+
upload_io_file = UploadIO.new(file, AMMADO_FILE_POSTFIX_TO_TYPE[file_postfix], file_name)
|
10
|
+
code, response = api.post_multipart(resource_create_path, params.merge(coverImage: upload_io_file, signature: calculate_signature, apiKey: api.key))
|
11
|
+
@params.merge!(response)
|
12
|
+
return code == '201'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource_create_path
|
17
|
+
"/v1/fundraiser/#{fundraiser_id}/coverimage"
|
18
|
+
end
|
19
|
+
|
20
|
+
def calculate_signature
|
21
|
+
Rails.logger.info('Calculate signature for ' + @params.to_s)
|
22
|
+
signature_parts = []
|
23
|
+
signature_parts << fundraiser_id
|
24
|
+
signature_parts << Base64.strict_encode64(file_name)
|
25
|
+
signature_parts << api.secret
|
26
|
+
plain_signature = signature_parts.flatten.join('.')
|
27
|
+
Rails.logger.info('Plain signature is ' + plain_signature)
|
28
|
+
return Digest::SHA1.hexdigest(plain_signature).upcase
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ammado
|
2
|
+
|
3
|
+
# https://api.ammado.com/#FundraiserModeratorEndpoint
|
4
|
+
class FundraiserModerator < ApiResource
|
5
|
+
|
6
|
+
def resource_create_path
|
7
|
+
"/v1/fundraiser/#{fundraiser_id}/moderators"
|
8
|
+
end
|
9
|
+
|
10
|
+
def calculate_signature
|
11
|
+
Rails.logger.info('Calculate signature for ' + @params.to_s)
|
12
|
+
signature_parts = []
|
13
|
+
signature_parts << fundraiser_id
|
14
|
+
signature_parts << email
|
15
|
+
signature_parts << api.secret
|
16
|
+
plain_signature = signature_parts.flatten.join('.')
|
17
|
+
Rails.logger.info('Plain signature is ' + plain_signature)
|
18
|
+
return Digest::SHA1.hexdigest(plain_signature).upcase
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/ammado.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
files = [
|
2
|
+
'api',
|
3
|
+
'api_error',
|
4
|
+
'api_resource',
|
5
|
+
'categories',
|
6
|
+
'fundraiser',
|
7
|
+
'fundraiser_avatar',
|
8
|
+
'fundraiser_cover',
|
9
|
+
'fundraiser_moderator',
|
10
|
+
'search'
|
11
|
+
]
|
12
|
+
|
13
|
+
AMMADO_FILE_POSTFIX_TO_TYPE = {
|
14
|
+
'jpg' => 'image/jpeg',
|
15
|
+
'png' => 'image/png'
|
16
|
+
}
|
17
|
+
|
18
|
+
files.map do |file|
|
19
|
+
require "ammado/#{file}"
|
20
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'test/unit'
|
27
|
+
require 'shoulda'
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
+
require 'ammado'
|
32
|
+
|
33
|
+
class Test::Unit::TestCase
|
34
|
+
end
|
data/test/test_ammado.rb
ADDED
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ammado
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Margus Pxrt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multipart-post
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: shoulda
|
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: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
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: Using Ammado API with Ruby (and Rails). https://api.ammado.com/
|
98
|
+
email: margus@wave.ee
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
files:
|
105
|
+
- .document
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- ammado.gemspec
|
112
|
+
- lib/ammado.rb
|
113
|
+
- lib/ammado/api.rb
|
114
|
+
- lib/ammado/api_error.rb
|
115
|
+
- lib/ammado/api_resource.rb
|
116
|
+
- lib/ammado/categories.rb
|
117
|
+
- lib/ammado/fundraiser.rb
|
118
|
+
- lib/ammado/fundraiser_avatar.rb
|
119
|
+
- lib/ammado/fundraiser_cover.rb
|
120
|
+
- lib/ammado/fundraiser_moderator.rb
|
121
|
+
- lib/ammado/search.rb
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_ammado.rb
|
124
|
+
homepage: http://github.com/mxrguspxrt/ammado
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.0.14
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Using Ammado API with Ruby (and Rails). https://api.ammado.com/
|
148
|
+
test_files: []
|