giftery 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
+ SHA256:
3
+ metadata.gz: c1ae7b1e5c459a46a7648f73755f07f023cc1fbba60fb042f8d2f92a4022cd9b
4
+ data.tar.gz: fde35925f3f6f9e4641eb724a76e283af8da29196adc1ff018cacde6642a134f
5
+ SHA512:
6
+ metadata.gz: 9d65a04e3081e8fbcf40b6cb1a9ee675903b3539ef79c544ee291be44226d1edf460cf1303b13c73f465884278a510c5cea87abc219d9fa4b39ff876a5039046
7
+ data.tar.gz: 046a44dfcd9757381bef05b2120793fb39029939fc18b1712109504be8be47820d63ae9f407469d198b738089ccc5ccc0ee52bb5fe264fb79ee2cbfc12214a58
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.5
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in giftery-ruby.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Boris Drazhzhov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # GifteryRuby
2
+ The service API documentation link: https://docs.giftery.tech/b2b-api/
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'giftery'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install giftery-ruby
19
+
20
+ ## Usage
21
+
22
+ Create client and call `test` operation:
23
+ ```ruby
24
+ client = Giftery::Client.new('<ID>', '<SECRET>')
25
+ # check available operations
26
+ client.test
27
+ ```
28
+ Example result:
29
+ ```ruby
30
+ {
31
+ "sample_text"=>"Test function works!",
32
+ "available_methods"=>[
33
+ "getProducts",
34
+ "getBalance",
35
+ "getCategories",
36
+ "getAddress",
37
+ "makeOrder",
38
+ "makeBulkOrder",
39
+ "getStatus",
40
+ "getCertificate",
41
+ "getCode",
42
+ "getReport",
43
+ "test",
44
+ "getLinks",
45
+ "makeTopUp",
46
+ "getTopUpStatus",
47
+ "getTopUpLimit"
48
+ ]
49
+ }
50
+ ```
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bundle install` to install dependencies.
55
+ Then, run `rake spec` to run the tests.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`.
58
+ To release a new version, update the version number in `version.rb`,
59
+ and then run `bundle exec rake release`, which will create a git tag for the version,
60
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bdrazhzhov/giftery-ruby.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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/giftery.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'giftery/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'giftery'
9
+ spec.version = Giftery::VERSION
10
+ spec.authors = ['Boris Drazhzhov']
11
+ spec.email = ['templar8@gmail.com']
12
+
13
+ spec.summary = 'Ruby implementation for Giftery (gift cards service) API'
14
+ spec.homepage = 'https://github.com/bdrazhzhov/giftery-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ spec.required_ruby_version = '>= 2.5.0'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata['homepage_uri'] = spec.homepage
23
+ spec.metadata['source_code_uri'] = 'https://github.com/bdrazhzhov/giftery-ruby'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # 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
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.require_paths = ['lib']
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.17'
37
+ spec.add_development_dependency 'rake', '~> 13.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_dependency 'digest', '~> 3.1.0'
40
+ spec.add_dependency 'http', '~> 5.0.0'
41
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'digest'
7
+
8
+ module Giftery
9
+ API_BASE_URL = 'https://ssl-api.giftery.ru'
10
+ INPUT_FORMAT = 'json'
11
+ OUTPUT_FORMAT = 'json'
12
+
13
+ # Giftery::Client class needs to be used
14
+ # for making requests to Giftery API
15
+ class Client
16
+ def initialize(client_id, secret)
17
+ @client_id = client_id
18
+ @secret = secret
19
+ end
20
+
21
+ def test
22
+ make_request('test')
23
+ end
24
+
25
+ def make_order(product_id, face, options = {})
26
+ data = options.merge!(product_id: product_id, face: face)
27
+ make_request('makeOrder', data)
28
+ end
29
+
30
+ def products
31
+ make_request('getProducts')
32
+ end
33
+
34
+ def certificate(queue_id)
35
+ make_request('getCertificate', queue_id: queue_id)
36
+ end
37
+
38
+ def code(queue_id, order_id)
39
+ make_request('getCode',
40
+ queue_id: queue_id,
41
+ order_id: order_id)
42
+ end
43
+
44
+ def links(queue_id, order_id)
45
+ make_request('getLinks',
46
+ queue_id: queue_id,
47
+ order_id: order_id)
48
+ end
49
+
50
+ def status(id)
51
+ make_request('getStatus', id: id)
52
+ end
53
+
54
+ def categories
55
+ make_request('getCategories')
56
+ end
57
+
58
+ def balance
59
+ make_request('getBalance')
60
+ end
61
+
62
+ def address(product_id, area_name, locality_name)
63
+ make_request('getBalance',
64
+ product_id: product_id,
65
+ area_name: area_name,
66
+ locality_name: locality_name)
67
+ end
68
+
69
+ private
70
+
71
+ def signature(method_name, data)
72
+ Digest::SHA256.hexdigest "#{method_name}#{data}#{@secret}"
73
+ end
74
+
75
+ def params(method_name, data)
76
+ data_json = data ? JSON.generate(data) : ''
77
+ {
78
+ id: @client_id,
79
+ cmd: method_name,
80
+ data: data_json,
81
+ sig: signature(method_name, data_json),
82
+ in: INPUT_FORMAT,
83
+ out: OUTPUT_FORMAT
84
+ }
85
+ end
86
+
87
+ def make_request(method_name, data = nil)
88
+ response = HTTP.get("#{API_BASE_URL}/?#{URI.encode_www_form(params(method_name, data))}")
89
+ result = JSON.parse(response.to_s)
90
+ raise result['error']['text'] unless result['status'] == 'ok'
91
+
92
+ result['data']
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Giftery
4
+ VERSION = '0.1.0'
5
+ end
data/lib/giftery.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'giftery/version'
4
+ require 'giftery/client'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: giftery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Boris Drazhzhov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-02-07 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.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: digest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: http
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.0
83
+ description:
84
+ email:
85
+ - templar8@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - giftery.gemspec
98
+ - lib/giftery.rb
99
+ - lib/giftery/client.rb
100
+ - lib/giftery/version.rb
101
+ homepage: https://github.com/bdrazhzhov/giftery-ruby
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ homepage_uri: https://github.com/bdrazhzhov/giftery-ruby
106
+ source_code_uri: https://github.com/bdrazhzhov/giftery-ruby
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.5.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.9
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Ruby implementation for Giftery (gift cards service) API
126
+ test_files: []