plate_api 0.4.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: 516481a1cbc16f2e26dcd8319b5b682c4f729217ff1f21f48f885ea7ca3f6f74
4
+ data.tar.gz: 6a5c9663a2185531bbb67b0f2c6a1c55941359ec233a14957ae7855ee83ed2a9
5
+ SHA512:
6
+ metadata.gz: 2a1894b50e1398d7ada99a89411a51ceadac86c564b3b6556c3491bfcd6c40a1058490d9f6e5dc360b917f238589e312ceb3d255c0b57f2cfdbbd447905be8ae
7
+ data.tar.gz: 6a71e32bfa9e55a080a8c06286b3c48b9d82c26961bcf280b69da1005309b409d2f3d1c889839053eb134b0173af060ebd8def0d959b4585711656493897f920
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.1
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 plate_api.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ plate_api (0.4.0)
5
+ faraday (~> 0.15.4)
6
+ faraday_middleware (~> 0.13.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.3)
12
+ faraday (0.15.4)
13
+ multipart-post (>= 1.2, < 3)
14
+ faraday_middleware (0.13.1)
15
+ faraday (>= 0.7.4, < 1.0)
16
+ multipart-post (2.0.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ plate_api!
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Stufingo
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,39 @@
1
+ # PlateApi
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/plate_api`. 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 'plate_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install plate_api
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]/plate_api.
36
+
37
+ ## License
38
+
39
+ 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/bin/console ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "plate_api"
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
+ def reload!(print = true)
14
+ puts 'Reloading ...' if print
15
+ # Main project directory.
16
+ root_dir = File.expand_path('..', __dir__)
17
+ # Directories within the project that should be reloaded.
18
+ reload_dirs = %w{lib}
19
+ # Loop through and reload every file in all relevant project directories.
20
+ reload_dirs.each do |dir|
21
+ Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
22
+ end
23
+ # Return true when complete.
24
+ true
25
+ end
26
+
27
+
28
+ require "irb"
29
+ IRB.start(__FILE__)
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,32 @@
1
+ require "plate_api/get_request"
2
+ require "plate_api/delete_request"
3
+ require "plate_api/post_request"
4
+ require "plate_api/put_request"
5
+
6
+ module PlateApi
7
+ class Connector
8
+
9
+
10
+ def initialize(public_key, secret_key, custom_server=nil)
11
+ @custom_server = custom_server
12
+ @public_key = public_key
13
+ @secret_key = secret_key
14
+ end
15
+
16
+ def get(url="", parameters={})
17
+ GetRequest.new(@public_key, @secret_key, url, parameters, @custom_server).send
18
+ end
19
+
20
+ def delete(url="", parameters={})
21
+ DeleteRequest.new(@public_key, @secret_key, url, parameters, @custom_server).send
22
+ end
23
+
24
+ def put(url="", put_params={})
25
+ PutRequest.new(@public_key, @secret_key, url, put_params, @custom_server).send
26
+ end
27
+
28
+ def post(url="", post_params={})
29
+ PostRequest.new(@public_key, @secret_key, url, post_params, @custom_server).send
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require "plate_api/request"
2
+
3
+ module PlateApi
4
+ class DeleteRequest < Request
5
+ def initialize(public_key, secret, path, parameters={}, custom_server=nil)
6
+ super(public_key, secret, "DELETE", path, custom_server)
7
+
8
+ sorted_params = parameters.to_a.sort_by{|x| x[0]}
9
+ @url_parameters = sorted_params.map{|x| "#{x[0]}=#{x[1]}"}.join("&")
10
+ end
11
+
12
+ def url_path
13
+ "#{@path}?#{@url_parameters}"
14
+ end
15
+
16
+ def url_parameters
17
+ @url_parameters
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require "plate_api/request"
2
+
3
+ module PlateApi
4
+ class GetRequest < Request
5
+ def initialize(public_key, secret, path, parameters={}, custom_server=nil)
6
+ super(public_key, secret, "GET", path, custom_server)
7
+
8
+ sorted_params = parameters.to_a.sort_by{|x| x[0]}
9
+ @url_parameters = sorted_params.map{|x| "#{x[0]}=#{x[1]}"}.join("&")
10
+ end
11
+
12
+ def url_path
13
+ "#{@path}?#{@url_parameters}"
14
+ end
15
+
16
+ def url_parameters
17
+ @url_parameters
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require "plate_api/request"
2
+
3
+ module PlateApi
4
+ class PostRequest < Request
5
+
6
+ def initialize(public_key, secret, path, parameters={}, custom_server=nil)
7
+ super(public_key, secret, "POST", path, custom_server)
8
+
9
+ @post_parameters = parameters.to_json
10
+ end
11
+
12
+ def extra_request_options(request)
13
+ request.headers['Content-Type'] = 'application/json'
14
+ request.body = @post_parameters
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require "plate_api/request"
2
+
3
+ module PlateApi
4
+ class PutRequest < Request
5
+
6
+ def initialize(public_key, secret, path, parameters={}, custom_server=nil)
7
+ super(public_key, secret, "PUT", path, custom_server)
8
+
9
+ @put_parameters = parameters.to_json
10
+ end
11
+
12
+ def extra_request_options(request)
13
+ request.headers['Content-Type'] = 'application/json'
14
+ request.body = @put_parameters
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,69 @@
1
+ require "faraday"
2
+ require 'faraday_middleware'
3
+ require 'time'
4
+ require "base64"
5
+ require "openssl"
6
+
7
+
8
+ module PlateApi
9
+ class Request
10
+ DefaultApiBaseEndpoint = "https://www.startwithplate.com/api/v2"
11
+
12
+ def initialize(public_key, secret, method, path, custom_server=nil)
13
+ base_api_endpoint = custom_server ? custom_server : DefaultApiBaseEndpoint
14
+
15
+ @connection = ::Faraday.new(url: base_api_endpoint) do |faraday|
16
+ faraday.response :json
17
+ faraday.adapter Faraday.default_adapter
18
+ end
19
+
20
+ @public_key = public_key
21
+ @secret = secret
22
+ @method = method
23
+ @path = strip_path(path)
24
+ end
25
+
26
+ def send
27
+ response = @connection.send(@method.downcase) do |request|
28
+ request.url url_path
29
+ request.headers['Date'] = request_date
30
+ request.headers['Authorization'] = calculate_signature
31
+ request.headers['Content-Type'] = 'application/json'
32
+ extra_request_options(request)
33
+ end
34
+
35
+ return response.body
36
+ end
37
+
38
+ def request_date
39
+ @date ||= Time.now.httpdate
40
+ end
41
+
42
+ def calculate_signature
43
+ string_to_sign = "#{@method}\n" +
44
+ "#{@connection.host}\n" +
45
+ "#{@connection.path_prefix}/#{@path}\n" +
46
+ "#{url_parameters}\n" +
47
+ "#{request_date}"
48
+ signature = Base64.strict_encode64(OpenSSL::HMAC.digest("SHA512", @secret, string_to_sign))
49
+ return "hmac #{@public_key}:#{signature}"
50
+ end
51
+
52
+ private
53
+
54
+ def url_path
55
+ @path
56
+ end
57
+
58
+ def url_parameters
59
+ ""
60
+ end
61
+
62
+ def extra_request_options(request)
63
+ end
64
+
65
+ def strip_path(path)
66
+ path.gsub(/^\/|\/$/, '')
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module PlateApi
2
+ VERSION = "0.4.0"
3
+ end
data/lib/plate_api.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "plate_api/version"
2
+ require "plate_api/connector"
3
+
4
+ module PlateApi
5
+ end
data/plate_api.gemspec ADDED
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "plate_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'plate_api'
8
+ spec.version = PlateApi::VERSION
9
+ spec.date = '2019-01-05'
10
+ spec.summary = "Connector for the Plate API"
11
+ spec.description = "This gem can be used to connect to the Plate API. It takes care
12
+ of the authentication procedure. "
13
+ spec.authors = ["David Kortleven"]
14
+ spec.email = 'david@getplate.com'
15
+ spec.files = ["lib/plate_api.rb"]
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_dependency "faraday", "~> 0.15.4"
35
+ spec.add_dependency "faraday_middleware", "~> 0.13.1"
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.16"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "rspec", "~> 3.0"
40
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plate_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - David Kortleven
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: "This gem can be used to connect to the Plate API. It takes care\n of
84
+ the authentication procedure. "
85
+ email: david@getplate.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
+ - bin/console
99
+ - bin/setup
100
+ - lib/plate_api.rb
101
+ - lib/plate_api/connector.rb
102
+ - lib/plate_api/delete_request.rb
103
+ - lib/plate_api/get_request.rb
104
+ - lib/plate_api/post_request.rb
105
+ - lib/plate_api/put_request.rb
106
+ - lib/plate_api/request.rb
107
+ - lib/plate_api/version.rb
108
+ - plate_api.gemspec
109
+ homepage:
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ allowed_push_host: https://rubygems.org
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Connector for the Plate API
134
+ test_files: []