rickai 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: 19664e07f91ace2acc8e0d04bb2125f9758b44482d9379f007db7cf1e1ad8282
4
+ data.tar.gz: 9c5bb61720728d2f798d792c8c142bfe9a06671871aa7dc98a51b907637bb11a
5
+ SHA512:
6
+ metadata.gz: c128861ce246c2a53ec4547750f332c3b52711c2feaca8b17bc05db38ff6345af3a1875a0f4a5f1048c2dc6228c3edc1748b1477496c45baea1e30cb976b8559
7
+ data.tar.gz: 434aae8b300d00f7373d45222373949cd22981c7a9ca43c38fdf0de2060481b9f356829022120733f1dd3891404865de9dc20c81318106499b75e8a5cdec2b41
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,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rickai.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rickai (0.1.0)
5
+ multi_json (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.3)
15
+ hashdiff (0.3.7)
16
+ multi_json (1.13.1)
17
+ public_suffix (3.0.3)
18
+ rake (10.5.0)
19
+ rspec (3.8.0)
20
+ rspec-core (~> 3.8.0)
21
+ rspec-expectations (~> 3.8.0)
22
+ rspec-mocks (~> 3.8.0)
23
+ rspec-core (3.8.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-expectations (3.8.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-mocks (3.8.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-support (3.8.0)
32
+ safe_yaml (1.0.4)
33
+ webmock (3.4.2)
34
+ addressable (>= 2.3.6)
35
+ crack (>= 0.3.2)
36
+ hashdiff
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.16)
43
+ rake (~> 10.0)
44
+ rickai!
45
+ rspec (~> 3.0)
46
+ webmock (~> 3.4.2)
47
+
48
+ BUNDLED WITH
49
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Anton Zagorskii
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,50 @@
1
+ # Rickai
2
+
3
+ Gem which will help you to do integration with Rick.io the fastest way
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rickai'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rickai
20
+
21
+ ## Usage
22
+
23
+ For creating of instance you need to call
24
+
25
+ ```ruby
26
+ client = RickAi::Client.new(agent_url)
27
+ ```
28
+
29
+ For calling action of update you just can call
30
+ ```ruby
31
+ client.update(your_attributes)
32
+ ```
33
+
34
+ For calling action of create you just can call
35
+ ```ruby
36
+ client.create(your_attributes)
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Clone your fork (git clone git@github.com:MY_USERNAME/customerio-ruby.git && cd customerio-ruby)
43
+ 3. Create your feature branch (git checkout -b my-new-feature)
44
+ 4. Commit your changes (git commit -am 'Added some feature')
45
+ 5. Push to the branch (git push origin my-new-feature)
46
+ 6. Create new Pull Request
47
+
48
+ ## License
49
+
50
+ 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
@@ -0,0 +1,66 @@
1
+ require 'net/http'
2
+ require 'multi_json'
3
+
4
+ module RickAi
5
+ DEFAULT_BASE_URI = 'https://exchange.appcraft.ru'
6
+ DEFAULT_TIMEOUT = 10
7
+
8
+ class Client
9
+ class InvalidResponse < RuntimeError; end
10
+
11
+ def initialize(agent_url, options = {})
12
+ @agent_url = agent_url
13
+ @base_uri = options[:base_uri] || DEFAULT_BASE_URI
14
+ @timeout = options[:timeout] || DEFAULT_TIMEOUT
15
+ end
16
+
17
+ def update(attributes)
18
+ verify_response(request(url_update, attributes))
19
+ end
20
+
21
+ def create(attributes)
22
+ verify_response(request(url_create, attributes))
23
+ end
24
+
25
+ private
26
+
27
+ def url_create
28
+ "/transactions/#{@agent_url}/create"
29
+ end
30
+
31
+ def url_update
32
+ "/transactions/#{@agent_url}/update"
33
+ end
34
+
35
+ def verify_response(response)
36
+ if response.code.to_i >= 200 && response.code.to_i < 300
37
+ response
38
+ else
39
+ raise InvalidResponse.new("Rick.ai API returned an invalid response: #{response.code} - #{response.message}")
40
+ end
41
+ end
42
+
43
+ def request(path, body = nil, headers = {})
44
+ uri = URI.join(@base_uri, path)
45
+
46
+ session = Net::HTTP.new(uri.host, uri.port)
47
+ session.use_ssl = (uri.scheme == 'https')
48
+ session.open_timeout = @timeout
49
+ session.read_timeout = @timeout
50
+
51
+ req = Net::HTTP::Post.new(uri.path)
52
+ req.initialize_http_header(headers)
53
+
54
+ req.add_field('Content-Type', 'application/json')
55
+
56
+ unless body.nil?
57
+ attributes = Hash[body.map { |(k, v)| [k.to_sym, v] }]
58
+ req.body = MultiJson.dump(attributes) unless body.nil?
59
+ end
60
+
61
+ session.start do |http|
62
+ http.request(req)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Rickai
2
+ VERSION = '0.1.0'
3
+ end
data/lib/rickai.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rickai/version'
2
+
3
+ module Rickai
4
+ require 'rickai/client'
5
+ end
data/rickai.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rickai/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rickai"
8
+ spec.version = Rickai::VERSION
9
+ spec.authors = ["Anton Zagorskii"]
10
+ spec.email = ["zagorskiianton@gmail.com"]
11
+
12
+ spec.summary = %q{Rickai gem does communicating with API easier}
13
+ spec.homepage = "https://github.com/antonzagorskii"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency("multi_json", "~> 1.0")
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency("webmock", "~> 3.4.2")
31
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rickai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anton Zagorskii
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.2
83
+ description:
84
+ email:
85
+ - zagorskiianton@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/rickai.rb
99
+ - lib/rickai/client.rb
100
+ - lib/rickai/version.rb
101
+ - rickai.gemspec
102
+ homepage: https://github.com/antonzagorskii
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Rickai gem does communicating with API easier
126
+ test_files: []