tmapi 0.0.1

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: '018b9a91fe49e1bd5b08bcbd881f1f461ece20d0'
4
+ data.tar.gz: 900a42a3678da59e534fe0e2bac78d549644a052
5
+ SHA512:
6
+ metadata.gz: 53b5401c92659815fcc766590f1bb78dd2d43e0e0000d1f9f9b885ea548dc9ca79178aca349ad68e2f303ffe630d26a53214d3264aaa8a6951cf782ac0f24203
7
+ data.tar.gz: 8ac13fa0282fa301d07838f1e4c4bca7fd2863fa032298a4c09fa72d1857bd5d1d0494d8ed51682a78b4c871e96c75c5b56cb2fe4f9f67f2910c4044246b6469
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Style/FrozenStringLiteralComment:
4
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ before_install: gem install bundler -v 1.13.6
4
+ notifications:
5
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'httparty'
4
+ gem 'nokogiri'
5
+
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tmapi (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.0)
10
+ public_suffix (~> 2.0, >= 2.0.2)
11
+ ast (2.3.0)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ hashdiff (0.3.2)
15
+ httparty (0.14.0)
16
+ multi_xml (>= 0.5.2)
17
+ mini_portile2 (2.1.0)
18
+ minitest (5.10.1)
19
+ multi_xml (0.5.5)
20
+ nokogiri (1.6.8.1)
21
+ mini_portile2 (~> 2.1.0)
22
+ parser (2.4.0.0)
23
+ ast (~> 2.2)
24
+ powerpack (0.1.1)
25
+ public_suffix (2.0.4)
26
+ rainbow (2.2.1)
27
+ rake (10.5.0)
28
+ rubocop (0.47.1)
29
+ parser (>= 2.3.3.1, < 3.0)
30
+ powerpack (~> 0.1)
31
+ rainbow (>= 1.99.1, < 3.0)
32
+ ruby-progressbar (~> 1.7)
33
+ unicode-display_width (~> 1.0, >= 1.0.1)
34
+ ruby-progressbar (1.8.1)
35
+ safe_yaml (1.0.4)
36
+ unicode-display_width (1.1.3)
37
+ webmock (2.3.1)
38
+ addressable (>= 2.3.6)
39
+ crack (>= 0.3.2)
40
+ hashdiff
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.13)
47
+ httparty
48
+ minitest (~> 5.0)
49
+ nokogiri
50
+ rake (~> 10.0)
51
+ rubocop (~> 0)
52
+ tmapi!
53
+ webmock (~> 2.3)
54
+
55
+ BUNDLED WITH
56
+ 1.13.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Rinat Garifullin
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,43 @@
1
+ # TmAPI
2
+
3
+ Wrapper for TM API ([Taxi Master](http://taxi-master.com)) written in Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tmapi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tmapi
20
+
21
+ ## Usage
22
+
23
+ First you should initialize a new class with API URL and unique key of customer. After this you can call API methods.
24
+
25
+ Example:
26
+ ```ruby
27
+ api = TMAPI('url', 'key')
28
+ api.change_order_state(order_id, new_state)
29
+ ```
30
+
31
+ Optionally you can disable SSL verification (enabled by default):
32
+ ```ruby
33
+ api = TMAPI('url', 'key', false)
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rgarifullin/tmapi.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tmapi'
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,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/lib/tmapi.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+ require 'logger'
4
+
5
+ class TMAPI
6
+ def initialize(url, key, ssl = true)
7
+ @url = url
8
+ @key = key
9
+ @ssl = ssl
10
+ @logger = TMAPI.logger || Logger.new(STDOUT)
11
+ end
12
+
13
+ def change_order_state(order_id, state)
14
+ params = { order_id: order_id, need_state: state }
15
+ params[:signature] = signature(params)
16
+
17
+ begin
18
+ response = HTTParty.post("#{@url}/change_order_state", body: params,
19
+ verify: @ssl)
20
+ result = Nokogiri::XML(response.body)
21
+ if response.success? && result.at_css('code')&.content.to_i.zero?
22
+ result.at_css('data')&.at_css('NEW_STATE')&.content.to_i == state
23
+ else
24
+ false
25
+ end
26
+ rescue Errno::ECONNREFUSED => ex
27
+ @logger.fatal(ex)
28
+ false
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ class << self
35
+ attr_accessor :logger
36
+ end
37
+
38
+ def url_params(params)
39
+ URI.encode_www_form(params)
40
+ end
41
+
42
+ def signature(params)
43
+ Digest::MD5.hexdigest(url_params(params) + @key)
44
+ end
45
+
46
+ if defined?(Rails::Railtie)
47
+ class Railtie < Rails::Railtie
48
+ initializer 'TmAPI.logger' do
49
+ TMAPI.logger = Rails.logger
50
+ end
51
+ end
52
+ end
53
+ end
data/tmapi.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'tmapi'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Rinat Garifullin']
9
+ spec.email = ['ringarifullin@gmail.com']
10
+
11
+ spec.summary = 'Wrapper for TM API'
12
+ spec.description = 'Wrapper for TM HTTP API http://taxi-master.com/'
13
+ spec.homepage = 'https://github.com/rgarifullin/tmapi'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.13'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'minitest', '~> 5.0'
26
+ spec.add_development_dependency 'webmock', '~> 2.3'
27
+ spec.add_development_dependency 'rubocop', '~> 0'
28
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rinat Garifullin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-21 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Wrapper for TM HTTP API http://taxi-master.com/
84
+ email:
85
+ - ringarifullin@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".ruby-version"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/tmapi.rb
102
+ - tmapi.gemspec
103
+ homepage: https://github.com/rgarifullin/tmapi
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
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: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.5.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Wrapper for TM API
127
+ test_files: []