izi_plagiarism_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5bf58de1b880890d18c76cb872907adc11277c98
4
+ data.tar.gz: 21833689d1794608f4d6fb32b2909addcc768431
5
+ SHA512:
6
+ metadata.gz: 4d9f09759c9db8e1a29bcad92e28be0ffd46d08d6eedaf58916dd6f7732418d5f55270bf0b2633b519481cdb52ab8a8953398c0e6e2c84cfe1ac5415d4a6091b
7
+ data.tar.gz: 36b8c2f92b745dd0ff8a16e1a4c0aaa69cdb59466c5c6cd010be228d9e1f738b812d41a3323861183c5fbef5b67ca39f27b2801143e84bbd1ad036ef9dd272ea
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 IzikAJ
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Plagiarism::Client
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'plagiarism-client'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install plagiarism-client
22
+ ```
23
+
24
+ ## Configuration
25
+ ```ruby
26
+ # config/initializers/plagiarism.rb
27
+ Plagiarism::Client.configure do |client|
28
+ client.endpoint = ENV['PLAGIARISM_API_ENDPOINT']
29
+ client.token = ENV['PLAGIARISM_API_KEY']
30
+ client.secret = ENV['PLAGIARISM_API_SECRET']
31
+ end
32
+ ```
33
+
34
+ ## Contributing
35
+ Contribution directions go here.
36
+
37
+ ## License
38
+ 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,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Plagiarism::Client'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'client/engine'
3
+
4
+ module Plagiarism
5
+ module Client
6
+ class << self
7
+ attr_accessor :endpoint, :token, :secret
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'signed_request'
4
+ require_relative 'report'
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'signed_request'
4
+
5
+ module Plagiarism
6
+ module Client
7
+ class Report
8
+ class << self
9
+ include SignedRequest
10
+
11
+ DATETIME_FIELDS = %w[
12
+ created_at
13
+ completed_at
14
+ ].freeze
15
+
16
+ def create(data = {})
17
+ structed post('/api/v1/reports', body: data)
18
+ end
19
+
20
+ def show(report_id)
21
+ structed get("/api/v1/reports/#{report_id}")
22
+ end
23
+
24
+ private
25
+
26
+ def structed(data = {})
27
+ obj = OpenStruct.new(data)
28
+
29
+ DATETIME_FIELDS.each do |field|
30
+ next if obj[field].blank? || !obj[field].is_a?(String)
31
+ obj[field] = Time.zone.parse(obj[field])
32
+ end
33
+
34
+ obj
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'httparty'
5
+ require 'api_signature'
6
+
7
+ module Plagiarism
8
+ module Client
9
+ module SignedRequest
10
+ protected
11
+
12
+ HEADER_KEYS = ApiSignature::Request::HEADER_KEYS
13
+
14
+ %w[get post put delete].each do |kind|
15
+ define_method kind do |path, **xargs|
16
+ headers = xargs.fetch(:headers, {})
17
+ headers = add_signature(headers, kind, path)
18
+ xargs[:headers] = headers
19
+ fullpath = File.join(Plagiarism::Client.endpoint, path)
20
+
21
+ response = HTTParty.send(kind, fullpath, **xargs)
22
+ JSON.parse(response.body)
23
+ end
24
+ end
25
+
26
+ def add_signature(headers, request_method, path)
27
+ options = signature_options(headers, request_method, path)
28
+
29
+ HEADER_KEYS.each do |kind, header|
30
+ headers[normalize_key(header)] = options[kind].to_s
31
+ end
32
+
33
+ headers
34
+ end
35
+
36
+ def signature_options(headers, request_method, path)
37
+ options = {
38
+ path: path,
39
+ request_method: request_method.to_s.upcase,
40
+ access_key: Plagiarism::Client.token,
41
+ timestamp: timestamp_for_options(headers)
42
+ }.with_indifferent_access
43
+
44
+ options[:signature] = generate_signature(options)
45
+
46
+ options
47
+ end
48
+
49
+ def timestamp_for_options(headers)
50
+ header_key = HEADER_KEYS[:timestamp].gsub(/^HTTP_/, '')
51
+
52
+ return headers[header_key] if headers.key? header_key
53
+ Time.zone.now.to_i
54
+ end
55
+
56
+ def generate_signature(options)
57
+ ApiSignature::Generator
58
+ .new(options)
59
+ .generate_signature(Plagiarism::Client.secret)
60
+ end
61
+
62
+ private
63
+
64
+ def normalize_key(key)
65
+ key.gsub(/^HTTP_/i, '').tr('_', '-').downcase
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ module Plagiarism
2
+ module Client
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :plagiarism_client do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: izi_plagiarism_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - IzikAJ
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: api_signature
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Description of Plagiarism::Client.
42
+ email:
43
+ - izikaj@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/plagiarism/client.rb
52
+ - lib/plagiarism/client/engine.rb
53
+ - lib/plagiarism/client/report.rb
54
+ - lib/plagiarism/client/signed_request.rb
55
+ - lib/plagiarism/client/version.rb
56
+ - lib/tasks/plagiarism/client_tasks.rake
57
+ homepage: http://example.com
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.6.14.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Summary of Plagiarism::Client.
81
+ test_files: []