darujme_cz 0.1.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f8ec4b523429634b11709ae103a9eb3e31ee7f60f7d3ca960f354c6f9cc7c88
4
- data.tar.gz: c491df332c6065165837be87c44fa64acc13a4c70d31f834def26735ef7840a5
3
+ metadata.gz: 452801c43b67be3a0d14199311717e1616b9f7b8e966119993b2f1087e6d8257
4
+ data.tar.gz: 4218afe511c1accfc6533cbfda5db7db086cf42e4dfde730a01f331d5141840a
5
5
  SHA512:
6
- metadata.gz: 65183b12b97591eb3da72459f9d86ea9dd0d9b7ddecf81a77609e8eeb73d087592bed8b33dc4f552c0939cf3a9fa6fa7721afcdd30f253bd7ac022ceacf287d6
7
- data.tar.gz: a474254a286f346c83adfd51812d40d202df9efda4208cc5def3c2ab88e831edad18f492197689cac9ccad5b48f46f77f69e27a7579a8a87aa4d305eee8a2adf
6
+ metadata.gz: d60d4ba973a7305f54f501d754bd868085f11798f0a2252d20450f7c926b67b81613d30ec6d987fcb468a702e542808b930ad42ddd0538bd7b0dd06d2a7d1463
7
+ data.tar.gz: 7e0ec06313c035798722f82ad92539b2cbb7fd60a54cec1956af71f5083b3f8d821001e9d863e7d61794e4bfc0cbd1da65a6e0c14cc3901779a6efb3e041cd9a
@@ -0,0 +1,23 @@
1
+ name: ci
2
+ on: [push]
3
+ jobs:
4
+ # https://docs.knapsackpro.com/2021/how-to-run-ruby-on-rails-tests-on-github-actions-using-rspec
5
+ test:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
10
+ ruby: [ 2.6, 2.7, '3.0' ]
11
+ runs-on: ubuntu-latest
12
+ env: # Rails verifies the time zone in DB is the same as the time zone of the Rails app
13
+ TZ: "Europe/Prague"
14
+ steps:
15
+ - name: Checkout code
16
+ uses: actions/checkout@v2
17
+ - name: Setup Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+ - name: RSpec
23
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -1,8 +1,16 @@
1
- Rails:
2
- Enabled: true
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
3
11
  AllCops:
4
- TargetRubyVersion: 2.3
5
-
12
+ NewCops: enable
13
+ TargetRubyVersion: 2.5
6
14
  Layout/MultilineMethodCallIndentation:
7
15
  EnforcedStyle: indented_relative_to_receiver
8
16
 
@@ -15,8 +23,6 @@ Metrics/LineLength:
15
23
  Metrics/MethodLength:
16
24
  Enabled: false
17
25
 
18
- Style/BracesAroundHashParameters:
19
- EnforcedStyle: context_dependent
20
26
  Style/Documentation:
21
27
  Enabled: false
22
28
  Style/FrozenStringLiteralComment:
@@ -35,6 +41,3 @@ Style/SymbolArray:
35
41
  Enabled: false
36
42
  Style/EmptyMethod:
37
43
  EnforcedStyle: expanded
38
- Layout/IndentationConsistency:
39
- EnforcedStyle: rails
40
- # Enabled: false
data/CHANGELOG.md CHANGED
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
 
8
8
  ## [Unreleased]
9
+ ## [0.4.0] - 2019-08-25
10
+ ### Security
11
+ - rake 12.3.3+
12
+ ### Added
13
+ - ruby3.0 support
14
+ ## [0.3.0] - 2019-08-25
15
+ ### Added
16
+ - project
17
+ ## [0.2.0] - 2019-06-01
18
+ ### Changed
19
+ - Connection use hash-style args
9
20
  ## [0.1.2] - 2019-05-13
10
21
  ### Added
11
22
  - delegators in transaction and pledge
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/darujme_cz.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "darujme_cz/version"
4
4
 
@@ -8,12 +8,13 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Lukáš Pokorný"]
9
9
  spec.email = ["luk4s.pokorny@gmail.com"]
10
10
 
11
- spec.summary = 'Ruby library for work with Darujme.cz API'
12
- spec.description = 'Get pledges or transactions from your organization on Darujme.cz'
11
+ spec.summary = "Ruby library for work with Darujme.cz API"
12
+ spec.description = "Get pledges or transactions from your organization on Darujme.cz"
13
13
  spec.homepage = "https://github.com/luk4s/darujme_cz"
14
14
  spec.license = "GPL-3.0-or-later"
15
+ spec.required_ruby_version = '>= 2.5'
15
16
 
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
19
  if spec.respond_to?(:metadata)
19
20
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
@@ -28,20 +29,19 @@ Gem::Specification.new do |spec|
28
29
 
29
30
  # Specify which files should be added to the gem when it is released.
30
31
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
33
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
34
  end
34
- spec.test_files = Dir['spec/**/*']
35
+ spec.test_files = Dir["spec/**/*"]
35
36
  # spec.bindir = "exe"
36
37
  # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
38
  spec.require_paths = ["lib"]
38
39
 
39
- spec.add_dependency 'activesupport', '> 5.2'
40
- spec.add_dependency 'money', '~> 6.13'
41
- spec.add_dependency 'rest-client', '~> 2.0'
40
+ spec.add_dependency "activesupport", "> 5.2", "< 7"
41
+ spec.add_dependency "money", "~> 6.13"
42
+ spec.add_dependency "rest-client", "~> 2.0"
42
43
 
43
- spec.add_development_dependency "bundler", "~> 2.0"
44
- spec.add_development_dependency "rake", "~> 10.0"
45
- spec.add_development_dependency "rspec", "~> 3.0"
46
- spec.add_development_dependency('webmock', '~> 3.4')
44
+ spec.add_development_dependency "rake", ">=12.3.3"
45
+ spec.add_development_dependency "rspec", "~> 3.11"
46
+ spec.add_development_dependency "webmock", "~> 3.4"
47
47
  end
@@ -1,13 +1,12 @@
1
1
  module DarujmeCz
2
2
  class Address
3
-
4
3
  # @param [Hash] attributes
5
4
  def initialize(attributes)
6
5
  @source = attributes
7
6
  end
8
7
 
9
8
  def to_s
10
- "#{@source["street"]}\n#{@source["postCode"]} #{@source["city"]}\n#{@source["country"]}"
9
+ "#{@source['street']}\n#{@source['postCode']} #{@source['city']}\n#{@source['country']}"
11
10
  end
12
11
 
13
12
  # alias
@@ -20,6 +19,5 @@ module DarujmeCz
20
19
  @source[m]
21
20
  end
22
21
  end
23
-
24
22
  end
25
- end
23
+ end
@@ -1,6 +1,5 @@
1
1
  module DarujmeCz
2
2
  class Base
3
-
4
3
  # @abstract Define name of endpoint, which is also name of root element
5
4
  def self.endpoint
6
5
  raise NotImplementedError
@@ -8,17 +7,28 @@ module DarujmeCz
8
7
 
9
8
  # @param [Hash] params
10
9
  # @option params [Integer] organization_id (nil) ID of organization
11
- def self.all(**params)
10
+ def self.all(params = {})
12
11
  where params
13
12
  end
14
13
 
15
- def self.where(**params)
16
- c = Connection.new DarujmeCz.config.app_id, DarujmeCz.config.app_secret
14
+ def self.where(params = {})
15
+ data = connection(params).get "#{base_path(params)}/#{endpoint}-by-filter", params
16
+ data[endpoint].map { |i| new(i) }
17
+ end
18
+
19
+ def self.connection(params = {})
20
+ credentials = params.delete(:connection) || {
21
+ app_id: DarujmeCz.config.app_id,
22
+ api_key: DarujmeCz.config.app_secret,
23
+ }
24
+ Connection.new(**credentials)
25
+ end
26
+
27
+ def self.base_path(params = {})
17
28
  org = params.delete(:organization_id) || DarujmeCz.config.organization_id
18
29
  raise ArgumentError, "Missing organization ID" if org.nil?
19
30
 
20
- data = c.get "organization/#{org}/#{endpoint}-by-filter", params
21
- data[endpoint].map { |i| new(i) }
31
+ "organization/#{org}"
22
32
  end
23
33
 
24
34
  attr_reader :id
@@ -28,5 +38,13 @@ module DarujmeCz
28
38
  @source = attributes
29
39
  end
30
40
 
41
+ # @param [Array<String>] list
42
+ def self.define_attributes(list)
43
+ list.each do |attribute|
44
+ define_method attribute.underscore do
45
+ @source[attribute]
46
+ end
47
+ end
48
+ end
31
49
  end
32
- end
50
+ end
@@ -4,28 +4,27 @@ require 'uri'
4
4
 
5
5
  module DarujmeCz
6
6
  class Connection
7
-
8
7
  URL = "https://www.darujme.cz/api/v1"
9
8
 
10
9
  # @param [String] app_id
11
10
  # @param [String] api_key
12
- def initialize(app_id, api_key)
11
+ def initialize(app_id:, api_key:)
13
12
  @app_id = app_id
14
13
  @api_key = api_key
15
14
  end
16
15
 
17
16
  # @param [String] path
18
17
  # @param [Hash] params
19
- def get(path, **params)
18
+ def get(path, params = {})
20
19
  begin
21
20
  response = RestClient.get "#{URL}/#{path}", params: { apiId: @app_id, apiSecret: @api_key }.merge(params)
22
- rescue RestClient::Exception => ex
23
- handle_response_error(ex)
21
+ rescue RestClient::Exception => e
22
+ handle_response_error(e)
24
23
  end
25
24
  parse_response(response)
26
25
  end
27
26
 
28
- def post(path, **data)
27
+ def post(path, data = {})
29
28
  # @todo
30
29
  raise NotImplementedError
31
30
  end
@@ -36,15 +35,14 @@ module DarujmeCz
36
35
  # @raise [RestClient::Exception]
37
36
  def handle_response_error(exception)
38
37
  data = parse_response(exception.response)
39
- exception.message += "\n#{data["message"]}"
38
+ exception.message += "\n#{data['message']}"
40
39
  raise exception
41
40
  end
42
41
 
43
42
  def parse_response(response)
44
43
  JSON.parse(response.body)
45
- rescue JSON::ParserError => _ex
44
+ rescue JSON::ParserError => _e
46
45
  {}
47
46
  end
48
-
49
47
  end
50
- end
48
+ end
@@ -1,6 +1,5 @@
1
1
  module DarujmeCz
2
2
  class Donor
3
-
4
3
  delegate :city, :street, :post_code, :postal_code, :country, to: :address
5
4
  # @param [Hash] attributes
6
5
  def initialize(attributes)
@@ -20,6 +19,5 @@ module DarujmeCz
20
19
  @source[m]
21
20
  end
22
21
  end
23
-
24
22
  end
25
- end
23
+ end
@@ -1,13 +1,14 @@
1
1
  module DarujmeCz
2
2
  # @see https://www.darujme.cz/doc/api/v1/index.html#endpoint-get-organization-organizationid-pledges-by-filter
3
3
  class Pledge < Base
4
-
5
4
  delegate :name, :address, :city, :street, :post_code, :postal_code, :country, to: :donor
6
5
 
7
6
  def self.endpoint
8
7
  "pledges"
9
8
  end
10
9
 
10
+ define_attributes %w[organizationId projectId promotionId paymentMethod]
11
+
11
12
  # @param [Hash] attributes
12
13
  def initialize(attributes)
13
14
  @id = attributes["pledgeId"]
@@ -32,12 +33,6 @@ module DarujmeCz
32
33
  @source["pledgedAt"].to_time
33
34
  end
34
35
 
35
- %w[organizationId projectId promotionId paymentMethod].each do |m|
36
- define_method m.underscore do
37
- @source[m]
38
- end
39
- end
40
-
41
36
  def donor
42
37
  @donor ||= Donor.new @source["donor"]
43
38
  end
@@ -48,5 +43,8 @@ module DarujmeCz
48
43
  end
49
44
  end
50
45
 
46
+ def project
47
+ @project ||= Project.find project_id
48
+ end
51
49
  end
52
- end
50
+ end
@@ -0,0 +1,48 @@
1
+ module DarujmeCz
2
+ # @see https://www.darujme.cz/doc/api/v1/index.html#endpoint-get-project-projectid
3
+ class Project < Base
4
+ def self.endpoint
5
+ "project"
6
+ end
7
+
8
+ def self.find(id)
9
+ data = connection.get "project/#{id}"
10
+ new data[endpoint]
11
+ end
12
+
13
+ # @param [Hash] attributes
14
+ def initialize(attributes)
15
+ @id = attributes["projectId"]
16
+ super
17
+ end
18
+
19
+ def name(lang = "cs")
20
+ get_localized_attribute "title", lang
21
+ end
22
+
23
+ def organization
24
+ # TODO
25
+ end
26
+
27
+ def content(lang = "cs")
28
+ get_localized_attribute "content", lang
29
+ end
30
+
31
+ def synopsis(lang = "cs")
32
+ get_localized_attribute "synopsis", lang
33
+ end
34
+
35
+ private
36
+
37
+ def get_localized_attribute(attribute, lang)
38
+ value = @source[attribute]
39
+ if value.is_a?(Hash)
40
+ value[lang] || value.values.first
41
+ else
42
+ value
43
+ end
44
+ end
45
+ end
46
+ end
47
+ # project_id = 1201275
48
+ # project_id = 1584
@@ -1,7 +1,6 @@
1
1
  module DarujmeCz
2
2
  # @see https://www.darujme.cz/doc/api/v1/index.html#endpoint-get-organization-organizationid-transactions-by-filter
3
3
  class Transaction < Base
4
-
5
4
  def self.endpoint
6
5
  "transactions"
7
6
  end
@@ -50,4 +49,4 @@ module DarujmeCz
50
49
  end
51
50
  end
52
51
  end
53
- end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module DarujmeCz
2
- VERSION = "0.1.2"
2
+ VERSION = "0.4.0"
3
3
  end
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
@@ -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
+ }
@@ -1,13 +1,12 @@
1
1
  RSpec.describe DarujmeCz::Connection do
2
- subject { described_class.new "22", "8d948b1" }
2
+ subject { described_class.new app_id: "22", api_key: "8d948b1" }
3
3
 
4
4
  describe ".get" do
5
5
  it "get all" do
6
- stub_request(:get, "https://www.darujme.cz/api/v1/organization/22/pledges-by-filter?apiId=22&apiSecret=8d948b1").
7
- to_return(status: 200, body: file_fixture("pledges.json"))
6
+ stub_request(:get, "https://www.darujme.cz/api/v1/organization/22/pledges-by-filter?apiId=22&apiSecret=8d948b1")
7
+ .to_return(status: 200, body: file_fixture("pledges.json"))
8
8
  data = subject.get "organization/22/pledges-by-filter"
9
9
  expect(data).to include "pledges"
10
10
  end
11
11
  end
12
-
13
- end
12
+ end
@@ -29,5 +29,4 @@ RSpec.describe DarujmeCz::Donor do
29
29
  it "#postal_code" do
30
30
  expect(subject.postal_code).to eq "120 00"
31
31
  end
32
-
33
32
  end
@@ -2,8 +2,8 @@ require "rest-client"
2
2
  RSpec.describe DarujmeCz::Pledge do
3
3
  describe ".all" do
4
4
  it "get all" do
5
- stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/pledges-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}").
6
- to_return(status: 200, body: file_fixture("pledges.json"))
5
+ stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/pledges-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}")
6
+ .to_return(status: 200, body: file_fixture("pledges.json"))
7
7
 
8
8
  pledges = described_class.all
9
9
  expect(pledges).to be_a Array
@@ -18,15 +18,15 @@ RSpec.describe DarujmeCz::Pledge do
18
18
  it "without credentials" do
19
19
  DarujmeCz.config.app_id = nil
20
20
 
21
- stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/pledges-by-filter?apiId&apiSecret=#{DarujmeCz.config.app_secret}").
22
- to_return(status: 400, body: darujme_cz_response_error(message: "Missing required parameter").to_json)
21
+ stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/pledges-by-filter?apiId&apiSecret=#{DarujmeCz.config.app_secret}")
22
+ .to_return(status: 400, body: darujme_cz_response_error(message: "Missing required parameter").to_json)
23
23
 
24
24
  expect { described_class.all }.to raise_exception RestClient::BadRequest, "400 Bad Request\nMissing required parameter"
25
25
  end
26
26
 
27
27
  it "pass custom organization_id" do
28
- stub = stub_request(:get, "https://www.darujme.cz/api/v1/organization/33/pledges-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}").
29
- to_return(status: 200, body: file_fixture("pledges.json"))
28
+ stub = stub_request(:get, "https://www.darujme.cz/api/v1/organization/33/pledges-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}")
29
+ .to_return(status: 200, body: file_fixture("pledges.json"))
30
30
 
31
31
  described_class.all(organization_id: 33)
32
32
  expect(stub).to have_been_made
@@ -35,8 +35,8 @@ RSpec.describe DarujmeCz::Pledge do
35
35
 
36
36
  describe ".where" do
37
37
  it "fromOutgoingDate" do
38
- stub = stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/pledges-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}&fromOutgoingDate=#{Date.today.strftime("%Y-%m-%d")}").
39
- to_return(status: 200, body: file_fixture("pledges.json"))
38
+ stub = stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/pledges-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}&fromOutgoingDate=#{Date.today.strftime('%Y-%m-%d')}")
39
+ .to_return(status: 200, body: file_fixture("pledges.json"))
40
40
  described_class.where fromOutgoingDate: Date.today
41
41
 
42
42
  expect(stub).to have_been_made
@@ -47,10 +47,9 @@ RSpec.describe DarujmeCz::Pledge do
47
47
  subject { described_class.new json["pledges"][0] }
48
48
 
49
49
  describe "attributes" do
50
-
51
50
  it "inspect" do
52
51
  expect(subject.project_id).to eq 4563
53
- expect(subject.id).to eq 1203450
52
+ expect(subject.id).to eq 1_203_450
54
53
  end
55
54
  end
56
55
 
@@ -90,4 +89,11 @@ RSpec.describe DarujmeCz::Pledge do
90
89
  expect(subject.city).to eq "Praha"
91
90
  end
92
91
 
93
- end
92
+ describe "#project" do
93
+ before :each do
94
+ stub_request(:get, "https://www.darujme.cz/api/v1/project/4563?apiId=123&apiSecret=abcd")
95
+ .to_return(status: 200, body: { project: JSON.parse(file_fixture("project.json").read) }.to_json)
96
+ end
97
+ it { expect(subject.project).to be_a DarujmeCz::Project }
98
+ end
99
+ end
@@ -0,0 +1,17 @@
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
+ end
@@ -1,8 +1,8 @@
1
1
  RSpec.describe DarujmeCz::Transaction do
2
2
  describe ".all" do
3
3
  it "get all" do
4
- stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/transactions-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}").
5
- to_return(status: 200, body: file_fixture("transactions.json"))
4
+ stub_request(:get, "https://www.darujme.cz/api/v1/organization/#{DarujmeCz.config.organization_id}/transactions-by-filter?apiId=#{DarujmeCz.config.app_id}&apiSecret=#{DarujmeCz.config.app_secret}")
5
+ .to_return(status: 200, body: file_fixture("transactions.json"))
6
6
 
7
7
  pledges = described_class.all
8
8
  expect(pledges).to be_a Array
@@ -50,5 +50,4 @@ RSpec.describe DarujmeCz::Transaction do
50
50
  it { expect(subject.refund?).to eq true }
51
51
  it { expect(subject.pending?).to eq false }
52
52
  end
53
-
54
- end
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,7 @@ RSpec.configure do |config|
16
16
  c.syntax = :expect
17
17
  end
18
18
 
19
- Dir.glob(File.expand_path('../support/*.rb', __FILE__)).each do |file|
19
+ Dir.glob(File.expand_path('support/*.rb', __dir__)).sort.each do |file|
20
20
  require file
21
21
  end
22
22
  config.before(:each) do
@@ -24,5 +24,4 @@ RSpec.configure do |config|
24
24
  DarujmeCz.config.app_secret = "abcd"
25
25
  DarujmeCz.config.organization_id = "2"
26
26
  end
27
-
28
27
  end
@@ -4,4 +4,4 @@ end
4
4
 
5
5
  def darujme_cz_response_error(message:)
6
6
  { status: "error", responsibility: "client", message: message }
7
- end
7
+ 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.1.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukáš Pokorný
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-01 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: money
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -52,48 +58,34 @@ dependencies:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
60
  version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.0'
69
61
  - !ruby/object:Gem::Dependency
70
62
  name: rake
71
63
  requirement: !ruby/object:Gem::Requirement
72
64
  requirements:
73
- - - "~>"
65
+ - - ">="
74
66
  - !ruby/object:Gem::Version
75
- version: '10.0'
67
+ version: 12.3.3
76
68
  type: :development
77
69
  prerelease: false
78
70
  version_requirements: !ruby/object:Gem::Requirement
79
71
  requirements:
80
- - - "~>"
72
+ - - ">="
81
73
  - !ruby/object:Gem::Version
82
- version: '10.0'
74
+ version: 12.3.3
83
75
  - !ruby/object:Gem::Dependency
84
76
  name: rspec
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
79
  - - "~>"
88
80
  - !ruby/object:Gem::Version
89
- version: '3.0'
81
+ version: '3.11'
90
82
  type: :development
91
83
  prerelease: false
92
84
  version_requirements: !ruby/object:Gem::Requirement
93
85
  requirements:
94
86
  - - "~>"
95
87
  - !ruby/object:Gem::Version
96
- version: '3.0'
88
+ version: '3.11'
97
89
  - !ruby/object:Gem::Dependency
98
90
  name: webmock
99
91
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +107,7 @@ executables: []
115
107
  extensions: []
116
108
  extra_rdoc_files: []
117
109
  files:
110
+ - ".github/workflows/ci.yml"
118
111
  - ".gitignore"
119
112
  - ".rspec"
120
113
  - ".rubocop.yml"
@@ -134,15 +127,18 @@ files:
134
127
  - lib/darujme_cz/connection.rb
135
128
  - lib/darujme_cz/donor.rb
136
129
  - lib/darujme_cz/pledge.rb
130
+ - lib/darujme_cz/project.rb
137
131
  - lib/darujme_cz/transaction.rb
138
132
  - lib/darujme_cz/version.rb
139
133
  - spec/darujme_cz_spec.rb
140
134
  - spec/fixtures/files/donor.json
141
135
  - spec/fixtures/files/pledges.json
136
+ - spec/fixtures/files/project.json
142
137
  - spec/fixtures/files/transactions.json
143
138
  - spec/models/connect_spec.rb
144
139
  - spec/models/donor_spec.rb
145
140
  - spec/models/pledge_spec.rb
141
+ - spec/models/project_spec.rb
146
142
  - spec/models/transaction_spec.rb
147
143
  - spec/spec_helper.rb
148
144
  - spec/support/darujme.rb
@@ -154,7 +150,7 @@ metadata:
154
150
  homepage_uri: https://github.com/luk4s/darujme_cz
155
151
  source_code_uri: https://github.com/luk4s/darujme_cz
156
152
  changelog_uri: https://github.com/luk4s/darujme_cz/CHANGELOG.md
157
- post_install_message:
153
+ post_install_message:
158
154
  rdoc_options: []
159
155
  require_paths:
160
156
  - lib
@@ -162,25 +158,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
158
  requirements:
163
159
  - - ">="
164
160
  - !ruby/object:Gem::Version
165
- version: '0'
161
+ version: '2.5'
166
162
  required_rubygems_version: !ruby/object:Gem::Requirement
167
163
  requirements:
168
164
  - - ">="
169
165
  - !ruby/object:Gem::Version
170
166
  version: '0'
171
167
  requirements: []
172
- rubygems_version: 3.0.3
173
- signing_key:
168
+ rubygems_version: 3.3.8
169
+ signing_key:
174
170
  specification_version: 4
175
171
  summary: Ruby library for work with Darujme.cz API
176
172
  test_files:
177
- - spec/spec_helper.rb
173
+ - spec/darujme_cz_spec.rb
174
+ - spec/fixtures/files/donor.json
175
+ - spec/fixtures/files/pledges.json
176
+ - spec/fixtures/files/project.json
177
+ - spec/fixtures/files/transactions.json
178
178
  - spec/models/connect_spec.rb
179
- - spec/models/transaction_spec.rb
180
- - spec/models/pledge_spec.rb
181
179
  - spec/models/donor_spec.rb
180
+ - spec/models/pledge_spec.rb
181
+ - spec/models/project_spec.rb
182
+ - spec/models/transaction_spec.rb
183
+ - spec/spec_helper.rb
182
184
  - spec/support/darujme.rb
183
- - spec/fixtures/files/donor.json
184
- - spec/fixtures/files/transactions.json
185
- - spec/fixtures/files/pledges.json
186
- - spec/darujme_cz_spec.rb