darujme_cz 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/darujme_cz.rb +1 -0
- data/lib/darujme_cz/base.rb +22 -4
- data/lib/darujme_cz/connection.rb +1 -1
- data/lib/darujme_cz/pledge.rb +7 -7
- data/lib/darujme_cz/project.rb +50 -0
- data/lib/darujme_cz/version.rb +1 -1
- data/spec/fixtures/files/project.json +61 -0
- data/spec/models/pledge_spec.rb +9 -1
- data/spec/models/project_spec.rb +18 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 672a894bc35b2c7afe8fd3c787e113431f5aed47bd96d53aa3e228e45378f8f8
|
4
|
+
data.tar.gz: 12899c6230d630f4e2842b1892284e0de2a32560bc12c069faac41ed4c2790da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40e8351839a8dbf6005e22a2581d9013797ad6a3e85bfae43a7fe2d24577477bcba0d6353a8bca8b1a371d4f3f68893e427bd63477b6c99bcc3e3e9423b0c013
|
7
|
+
data.tar.gz: 860308c1dc3706f574f06740679ba26b91ea79bb8b3c80378ec3179708d4f6b69a9745b80519e23fbefad44380c59b74383a0347fcc8a33c307f80302586ae8d
|
data/CHANGELOG.md
CHANGED
data/lib/darujme_cz.rb
CHANGED
@@ -12,6 +12,7 @@ module DarujmeCz
|
|
12
12
|
autoload :Connection, "darujme_cz/connection"
|
13
13
|
autoload :Donor, "darujme_cz/donor"
|
14
14
|
autoload :Pledge, "darujme_cz/pledge"
|
15
|
+
autoload :Project, "darujme_cz/project"
|
15
16
|
autoload :Transaction, "darujme_cz/transaction"
|
16
17
|
|
17
18
|
include ActiveSupport::Configurable
|
data/lib/darujme_cz/base.rb
CHANGED
@@ -13,16 +13,23 @@ module DarujmeCz
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.where(**params)
|
16
|
+
data = connection(params).get "#{base_path(params)}/#{endpoint}-by-filter", params
|
17
|
+
data[endpoint].map { |i| new(i) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.connection(params = {})
|
16
21
|
credentials = params.delete(:connection) || {
|
17
22
|
app_id: DarujmeCz.config.app_id,
|
18
23
|
api_key: DarujmeCz.config.app_secret
|
19
24
|
}
|
20
|
-
|
25
|
+
Connection.new credentials
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.base_path(params = {})
|
21
29
|
org = params.delete(:organization_id) || DarujmeCz.config.organization_id
|
22
30
|
raise ArgumentError, "Missing organization ID" if org.nil?
|
23
31
|
|
24
|
-
|
25
|
-
data[endpoint].map { |i| new(i) }
|
32
|
+
"organization/#{org}"
|
26
33
|
end
|
27
34
|
|
28
35
|
attr_reader :id
|
@@ -32,5 +39,16 @@ module DarujmeCz
|
|
32
39
|
@source = attributes
|
33
40
|
end
|
34
41
|
|
42
|
+
private
|
43
|
+
|
44
|
+
# @param [Array<String>] list
|
45
|
+
def self.define_attributes(list)
|
46
|
+
list.each do |attribute|
|
47
|
+
define_method attribute.underscore do
|
48
|
+
@source[attribute]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
35
53
|
end
|
36
|
-
end
|
54
|
+
end
|
data/lib/darujme_cz/pledge.rb
CHANGED
@@ -8,6 +8,8 @@ module DarujmeCz
|
|
8
8
|
"pledges"
|
9
9
|
end
|
10
10
|
|
11
|
+
define_attributes %w[organizationId projectId promotionId paymentMethod]
|
12
|
+
|
11
13
|
# @param [Hash] attributes
|
12
14
|
def initialize(attributes)
|
13
15
|
@id = attributes["pledgeId"]
|
@@ -32,12 +34,6 @@ module DarujmeCz
|
|
32
34
|
@source["pledgedAt"].to_time
|
33
35
|
end
|
34
36
|
|
35
|
-
%w[organizationId projectId promotionId paymentMethod].each do |m|
|
36
|
-
define_method m.underscore do
|
37
|
-
@source[m]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
37
|
def donor
|
42
38
|
@donor ||= Donor.new @source["donor"]
|
43
39
|
end
|
@@ -48,5 +44,9 @@ module DarujmeCz
|
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
47
|
+
def project
|
48
|
+
@project ||= Project.find project_id
|
49
|
+
end
|
50
|
+
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module DarujmeCz
|
2
|
+
# @see https://www.darujme.cz/doc/api/v1/index.html#endpoint-get-project-projectid
|
3
|
+
class Project < Base
|
4
|
+
|
5
|
+
def self.endpoint
|
6
|
+
"project"
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find(id)
|
10
|
+
data = connection.get "project/#{id}"
|
11
|
+
new data[endpoint]
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Hash] attributes
|
15
|
+
def initialize(attributes)
|
16
|
+
@id = attributes["projectId"]
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def name(lang = "cs")
|
21
|
+
get_localized_attribute "title", lang
|
22
|
+
end
|
23
|
+
|
24
|
+
def organization
|
25
|
+
# TODO
|
26
|
+
end
|
27
|
+
|
28
|
+
def content(lang = "cs")
|
29
|
+
get_localized_attribute "content", lang
|
30
|
+
end
|
31
|
+
|
32
|
+
def synopsis(lang = "cs")
|
33
|
+
get_localized_attribute "synopsis", lang
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def get_localized_attribute(attribute, lang)
|
39
|
+
value = @source[attribute]
|
40
|
+
if value.is_a?(Hash)
|
41
|
+
value[lang] || value.values.first
|
42
|
+
else
|
43
|
+
value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# project_id = 1201275
|
50
|
+
# project_id = 1584
|
data/lib/darujme_cz/version.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
{
|
2
|
+
"projectId": 1201275,
|
3
|
+
"promotionId": null,
|
4
|
+
"organization": {
|
5
|
+
"organizationId": 434,
|
6
|
+
"name": "My organization",
|
7
|
+
"logo": {
|
8
|
+
"url": "https://s3.eu-central-1.amazonaws.com/uploads.darujme.cz/organization/logo/NF-square-200.jpg-1UjY2/RkTzbV6LLxuWZfmCZX.jpg"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
"collectedAmountEstimate": {
|
12
|
+
"cents": 12345,
|
13
|
+
"currency": "CZK"
|
14
|
+
},
|
15
|
+
"donorsCount": 123,
|
16
|
+
"title": {
|
17
|
+
"cs": "Název projektu",
|
18
|
+
"en": "Name of project"
|
19
|
+
},
|
20
|
+
"synopsis": {
|
21
|
+
"cs": "Lorem Ipsum je demonstrativní výplňový text používaný v tiskařském a knihařském průmyslu. Lorem Ipsum je považováno za standard v této oblasti už od začátku 16. století, kdy dnes neznámý tiskař vzal kusy textu a na jejich základě vytvořil speciální vzorovou knihu. Jeho odkaz nevydržel pouze pět století, on přežil i nástup elektronické sazby v podstatě beze změny.",
|
22
|
+
"en": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."
|
23
|
+
},
|
24
|
+
"content": {
|
25
|
+
"cs": "Lorem Ipsum je demonstrativní výplňový text používaný v tiskařském a knihařském průmyslu. Lorem Ipsum je považováno za standard v této oblasti už od začátku 16. století, kdy dnes neznámý tiskař vzal kusy textu a na jejich základě vytvořil speciální vzorovou knihu. Jeho odkaz nevydržel pouze pět století, on přežil i nástup elektronické sazby v podstatě beze změny",
|
26
|
+
"en": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged"
|
27
|
+
},
|
28
|
+
"targetAmount": null,
|
29
|
+
"activeUntil": null,
|
30
|
+
"imageHeader": {
|
31
|
+
"url": "https://s3.eu-central-1.amazonaws.com/uploads.darujme.cz/project/header/JogaSeniori-FondVedomi2019-C-AnnaSolcova.31.JPG-a828356b712c44353e2f648cd948389f.jpg"
|
32
|
+
},
|
33
|
+
"donateUrl": "https://www.darujme.cz/darovat/1201275",
|
34
|
+
"tags": [
|
35
|
+
{
|
36
|
+
"tagId": 1000010,
|
37
|
+
"label": {
|
38
|
+
"cs": "tag1",
|
39
|
+
"en": "the tag1"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"suggestedAmounts": [
|
44
|
+
{
|
45
|
+
"primaryAmount": {
|
46
|
+
"cents": 10,
|
47
|
+
"currency": "CZK"
|
48
|
+
},
|
49
|
+
"secondaryAmount": {
|
50
|
+
"cents": 20,
|
51
|
+
"currency": "EUR"
|
52
|
+
},
|
53
|
+
"description": {
|
54
|
+
"cs": "Navzdory všeobecnému přesvědčení Lorem Ipsum není náhodný text.",
|
55
|
+
"en": "Contrary to popular belief, Lorem Ipsum is not simply random text."
|
56
|
+
},
|
57
|
+
"default": true
|
58
|
+
}
|
59
|
+
],
|
60
|
+
"donationMatching": null
|
61
|
+
}
|
data/spec/models/pledge_spec.rb
CHANGED
@@ -90,4 +90,12 @@ RSpec.describe DarujmeCz::Pledge do
|
|
90
90
|
expect(subject.city).to eq "Praha"
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
describe "#project" do
|
94
|
+
before :each do
|
95
|
+
stub_request(:get, "https://www.darujme.cz/api/v1/project/4563?apiId=123&apiSecret=abcd").
|
96
|
+
to_return(status: 200, body: { project: JSON.parse(file_fixture("project.json").read) }.to_json)
|
97
|
+
end
|
98
|
+
it { expect(subject.project).to be_a DarujmeCz::Project }
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec.describe DarujmeCz::Project do
|
2
|
+
let(:attributes) { JSON.parse(file_fixture("project.json").read) }
|
3
|
+
|
4
|
+
subject { described_class.new attributes }
|
5
|
+
|
6
|
+
shared_examples "localized attributes" do |attribute_name, json_source = nil|
|
7
|
+
describe "##{attribute_name}" do
|
8
|
+
it { expect(subject.send(attribute_name)).to eq attributes[json_source || attribute_name]["cs"] }
|
9
|
+
it { expect(subject.send(attribute_name, "pl")).to eq attributes[json_source || attribute_name]["cs"] }
|
10
|
+
it { expect(subject.send(attribute_name, "en")).to eq attributes[json_source || attribute_name]["en"] }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it_behaves_like "localized attributes", "name", "title"
|
15
|
+
it_behaves_like "localized attributes", "content"
|
16
|
+
it_behaves_like "localized attributes", "synopsis"
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darujme_cz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -134,15 +134,18 @@ files:
|
|
134
134
|
- lib/darujme_cz/connection.rb
|
135
135
|
- lib/darujme_cz/donor.rb
|
136
136
|
- lib/darujme_cz/pledge.rb
|
137
|
+
- lib/darujme_cz/project.rb
|
137
138
|
- lib/darujme_cz/transaction.rb
|
138
139
|
- lib/darujme_cz/version.rb
|
139
140
|
- spec/darujme_cz_spec.rb
|
140
141
|
- spec/fixtures/files/donor.json
|
141
142
|
- spec/fixtures/files/pledges.json
|
143
|
+
- spec/fixtures/files/project.json
|
142
144
|
- spec/fixtures/files/transactions.json
|
143
145
|
- spec/models/connect_spec.rb
|
144
146
|
- spec/models/donor_spec.rb
|
145
147
|
- spec/models/pledge_spec.rb
|
148
|
+
- spec/models/project_spec.rb
|
146
149
|
- spec/models/transaction_spec.rb
|
147
150
|
- spec/spec_helper.rb
|
148
151
|
- spec/support/darujme.rb
|
@@ -169,17 +172,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
172
|
- !ruby/object:Gem::Version
|
170
173
|
version: '0'
|
171
174
|
requirements: []
|
172
|
-
rubygems_version: 3.0.
|
175
|
+
rubygems_version: 3.0.4
|
173
176
|
signing_key:
|
174
177
|
specification_version: 4
|
175
178
|
summary: Ruby library for work with Darujme.cz API
|
176
179
|
test_files:
|
177
180
|
- spec/spec_helper.rb
|
181
|
+
- spec/models/project_spec.rb
|
178
182
|
- spec/models/connect_spec.rb
|
179
183
|
- spec/models/transaction_spec.rb
|
180
184
|
- spec/models/pledge_spec.rb
|
181
185
|
- spec/models/donor_spec.rb
|
182
186
|
- spec/support/darujme.rb
|
187
|
+
- spec/fixtures/files/project.json
|
183
188
|
- spec/fixtures/files/donor.json
|
184
189
|
- spec/fixtures/files/transactions.json
|
185
190
|
- spec/fixtures/files/pledges.json
|