drebedengi-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f01fdee0023c4ade1709bb7cc6a79ac83ee3f79
4
+ data.tar.gz: dbbf04c17fbfceb3ea89e47ba48be61b8edacc89
5
+ SHA512:
6
+ metadata.gz: bb3cfb0267616a98462ca939ce71183db23cf2b6116345b9da84ec8ae15293b9df0f75c7dd1e228b478724de5a9d454816da323a3927b2c8e552454f1599a075
7
+ data.tar.gz: a97c90a725fc1aef51c918d24561624db02c5786eb86eb0f1e257e3e766b2f89e437781d1d7f86a6e74d4577514a64f7af048b8862d7a52c74058e1cfce83c80
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in drebedengi-rb.gemspec
4
+ gemspec
5
+
6
+ Bundler.setup(:default)
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Drebedengi::Rb
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/drebedengi/rb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'drebedengi-rb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install drebedengi-rb
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/drebedengi-rb.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "drebedengi/rb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'drebedengi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "drebedengi-rb"
8
+ spec.version = Drebedengi::VERSION
9
+ spec.authors = ["Sergio Tulentsev"]
10
+ spec.email = ["sergei.tulentsev@gmail.com"]
11
+
12
+ spec.summary = %q{Client library for http://www.drebedengi.ru}
13
+ spec.description = %q{Drebedengi is a finance-tracking application. Unfortunately, their API is SOAP-based. This gem shields you from the horrors of SOAP and aims to give you the ruby experience.}
14
+ spec.homepage = ""
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib", 'lib/drebedengi']
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+
25
+ spec.add_runtime_dependency 'savon', '~> 2.11'
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'drebedengi/version'
2
+ require 'drebedengi/client'
3
+
4
+ module Drebedengi
5
+
6
+ end
@@ -0,0 +1,59 @@
1
+ require 'savon'
2
+ require 'parameter_builders/base'
3
+ require 'parameter_builders/get_record_list'
4
+
5
+ require 'responses/base'
6
+ require 'responses/get_balance'
7
+ require 'responses/get_place_list'
8
+ require 'responses/get_record_list'
9
+
10
+ module Drebedengi
11
+ class Client
12
+
13
+ attr_accessor :api_creds
14
+
15
+ def initialize
16
+ @api_creds = {
17
+ apiId: 'demo_api',
18
+ login: 'demo@example.com',
19
+ pass: 'demo',
20
+ }
21
+ end
22
+
23
+ def get_balance
24
+ raw_response = client.call(:get_balance, message: api_creds)
25
+ Responses::GetBalance.new(raw_response.body).places
26
+ end
27
+
28
+ def get_place_list
29
+ raw_response = client.call(:get_place_list, message: api_creds)
30
+ Responses::GetPlaceList.new(raw_response.body).places
31
+ end
32
+
33
+ # Gets transactions
34
+ #
35
+ # @param id_list [Array] Get specific transactions by id
36
+ # @param period_from [Date] Period from
37
+ # @param period_to [Date] Period to
38
+ def get_record_list(**kwargs)
39
+ raw_response = client.call(
40
+ :get_record_list,
41
+ message: ParameterBuilders::GetRecordList.new(**kwargs),
42
+ soap_header: { "OpToken" => "secret" },
43
+ )
44
+
45
+ Responses::GetRecordList.new(raw_response.body).records
46
+ end
47
+
48
+ def client
49
+ @client ||= ::Savon.client(
50
+ wsdl: 'http://www.drebedengi.ru/soap/dd.wsdl',
51
+ # proxy: 'http://localhost:8888',
52
+ namespaces: {
53
+ 'xmlns:ns2' => 'http://xml.apache.org/xml-soap',
54
+ 'xmlns:SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
55
+ },
56
+ )
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,34 @@
1
+ require 'parameter_builders/concerns/type_formatters'
2
+
3
+ module ParameterBuilders
4
+ class Base
5
+ include ::ParameterBuilders::Concerns::TypeFormatters
6
+
7
+ private
8
+
9
+ def bool_param(key, value)
10
+ param(key, !!value, 'boolean')
11
+ end
12
+ alias_method :boolean_param, :bool_param
13
+
14
+ def date_param(key, value)
15
+ param(key, soap_date(value), 'date')
16
+ end
17
+
18
+ def int_param(key, value)
19
+ param(key, value, 'int')
20
+ end
21
+ alias_method :integer_param, :int_param
22
+
23
+ def param(key, value, soap_type)
24
+ builder.item do
25
+ builder.key({'xsi:type' => 'xsd:string'}, key)
26
+ builder.value({'xsi:type' => "xsd:#{soap_type}"}, value)
27
+ end
28
+ end
29
+
30
+ def builder
31
+ @builder ||= Builder::XmlMarkup.new
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module ParameterBuilders
2
+ module Concerns
3
+ module TypeFormatters
4
+ def soap_date(date)
5
+ date.strftime('%Y-%m-%d')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,72 @@
1
+ module ParameterBuilders
2
+ class GetRecordList < Base
3
+ attr_reader :id_list, :period_from, :period_to
4
+
5
+ def initialize(id_list: nil, period_from: nil, period_to: nil)
6
+ @id_list = id_list
7
+ @period_from = period_from
8
+ @period_to = period_to
9
+ end
10
+
11
+ def to_s
12
+
13
+ builder.apiId({ 'xsi:type' => 'xsd:string' }, 'demo_api')
14
+ builder.login({ 'xsi:type' => 'xsd:string' }, 'demo@example.com')
15
+ builder.pass({ 'xsi:type' => 'xsd:string' }, 'demo')
16
+
17
+ builder.params('xsi:type' => 'ns2:Map') do
18
+
19
+ boolean_param('is_report', false)
20
+ if period_from && period_to
21
+ date_param('period_from', period_from)
22
+ date_param('period_to', period_to)
23
+ integer_param('r_period', 0)
24
+ else
25
+ integer_param('r_period', 1)
26
+ end
27
+ integer_param('r_how', 1) # detailed, no grouping
28
+
29
+ # builder.item do
30
+ # builder.key({'xsi:type' => 'xsd:string'}, 'is_show_duty')
31
+ # builder.value({'xsi:type' => 'xsd:boolean'}, true)
32
+ # end
33
+ # builder.item do
34
+ # builder.key({'xsi:type' => 'xsd:string'}, 'r_period')
35
+ # builder.value({'xsi:type' => 'xsd:int'}, 8)
36
+ # end
37
+ # builder.item do
38
+ # builder.key({'xsi:type' => 'xsd:string'}, 'r_how')
39
+ # builder.value({'xsi:type' => 'xsd:int'}, 1)
40
+ # end
41
+ # builder.item do
42
+ # builder.key({'xsi:type' => 'xsd:string'}, 'r_what')
43
+ # builder.value({'xsi:type' => 'xsd:int'}, 6)
44
+ # end
45
+ # builder.item do
46
+ # builder.key({'xsi:type' => 'xsd:string'}, 'r_currency')
47
+ # builder.value({'xsi:type' => 'xsd:int'}, 0)
48
+ # end
49
+ # builder.item do
50
+ # builder.key({'xsi:type' => 'xsd:string'}, 'r_is_place')
51
+ # builder.value({'xsi:type' => 'xsd:int'}, 0)
52
+ # end
53
+ # builder.item do
54
+ # builder.key({'xsi:type' => 'xsd:string'}, 'r_is_tag')
55
+ # builder.value({'xsi:type' => 'xsd:int'}, 0)
56
+ # end
57
+ end
58
+
59
+ if id_list
60
+ builder.idList('xsi:type' => 'SOAP-ENC:Array') do
61
+ id_list.each do |id|
62
+ builder.item({ 'xsi:type' => 'xsd:string' }, id.to_s)
63
+ end
64
+ end
65
+ # else
66
+ # builder.idList('xsi:nil' => 'true')
67
+ end
68
+
69
+ builder.target!
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ require 'responses/concerns/type_conversions'
2
+
3
+ module Responses
4
+ class Base
5
+ include Concerns::TypeConversions
6
+
7
+
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module Responses
2
+ module Concerns
3
+ module TypeConversions
4
+ def autocast_value_for_key(key:, value:)
5
+ integer_keys = %w[id budget_family_id type icon_id parent_id sum place_id
6
+ budget_object_id currency_id operation_type group_id user_nuid]
7
+ boolean_keys = %w[is_hidden is_for_duty is_autohide is_duty is_credit_card
8
+ is_currency_change ]
9
+ date_keys = %w[operation_date]
10
+
11
+ case key
12
+ when *integer_keys
13
+ value && Integer(value)
14
+ when *boolean_keys
15
+ value == 't'
16
+ when *date_keys
17
+ ::Time.parse(value)
18
+ else
19
+ value
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'ostruct'
2
+
3
+ module Responses
4
+ class GetBalance < ::Responses::Base
5
+ attr_reader :places
6
+
7
+ def initialize(soap_hash)
8
+ @places = process(soap_hash)
9
+ end
10
+
11
+ private
12
+
13
+ def process(soap_hash)
14
+ soap_hash[:get_balance_response][:get_balance_return][:item].map do |hash|
15
+ hash[:item].each_with_object(OpenStruct.new) do |hash, place|
16
+ value = autocast_value_for_key(key: hash[:key], value: hash[:value])
17
+ place[hash[:key]] = value
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'ostruct'
2
+
3
+ module Responses
4
+ class GetPlaceList < ::Responses::Base
5
+ attr_reader :places
6
+
7
+ def initialize(soap_hash)
8
+ @places = process(soap_hash)
9
+ end
10
+
11
+ private
12
+
13
+ def process(soap_hash)
14
+ soap_hash[:get_place_list_response][:get_place_list_return][:item].map do |hash|
15
+ hash[:item].each_with_object(OpenStruct.new) do |hash, place|
16
+ value = autocast_value_for_key(key: hash[:key], value: hash[:value])
17
+ place[hash[:key]] = value
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'ostruct'
2
+
3
+ module Responses
4
+ class GetRecordList < ::Responses::Base
5
+ attr_reader :records
6
+
7
+ def initialize(soap_hash)
8
+ @records = process(soap_hash)
9
+ end
10
+
11
+ private
12
+
13
+ def process(soap_hash)
14
+ soap_hash[:get_record_list_response][:get_record_list_return][:item].map do |record_attributes|
15
+ record_attributes[:value][:item].each_with_object(OpenStruct.new) do |hash, record|
16
+ value = autocast_value_for_key(key: hash[:key], value: hash[:value])
17
+ record[hash[:key]] = value
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Drebedengi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drebedengi-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Tulentsev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-12 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: savon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.11'
69
+ description: Drebedengi is a finance-tracking application. Unfortunately, their API
70
+ is SOAP-based. This gem shields you from the horrors of SOAP and aims to give you
71
+ the ruby experience.
72
+ email:
73
+ - sergei.tulentsev@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - drebedengi-rb.gemspec
87
+ - lib/drebedengi-rb.rb
88
+ - lib/drebedengi/client.rb
89
+ - lib/drebedengi/parameter_builders/base.rb
90
+ - lib/drebedengi/parameter_builders/concerns/type_formatters.rb
91
+ - lib/drebedengi/parameter_builders/get_record_list.rb
92
+ - lib/drebedengi/responses/base.rb
93
+ - lib/drebedengi/responses/concerns/type_conversions.rb
94
+ - lib/drebedengi/responses/get_balance.rb
95
+ - lib/drebedengi/responses/get_place_list.rb
96
+ - lib/drebedengi/responses/get_record_list.rb
97
+ - lib/drebedengi/version.rb
98
+ homepage: ''
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ - lib/drebedengi
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Client library for http://www.drebedengi.ru
122
+ test_files: []