fusion-client 1.0.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
+ SHA1:
3
+ metadata.gz: 5dc988ff83dc4be66431788fe39677bbd8f767ef
4
+ data.tar.gz: cf687cf05566793eec656709acb1b2f22e47a619
5
+ SHA512:
6
+ metadata.gz: cae445521a8b189eb44dafcf8c541e500a1eb1b717e7c68b999cc5eef5e94911aa3f2dea2751e7946c228c7bc0a90a79b98faa4330a83508df19e827248e0323
7
+ data.tar.gz: a32c92442ac8381853bed24003f358d689cd3bc247679b7ee0bf1cd9f44afbfaa1bdd047a866baf32aa51c8ae899e30cd539c47b80c30b2784716f2c8f2e9c7c
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.14.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fusion-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Josh Starcher
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,41 @@
1
+ # Fusion::Client
2
+
3
+ This gem provides a client for the custom API that Calinoi has built on
4
+ top of Fusion Pro.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'fusion-client'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install fusion-client
21
+
22
+ ## Usage
23
+
24
+ [See the Usage page on the wiki](https://github.com/calinoi/fusion-client/wiki/Usage)
25
+
26
+ ## Development
27
+
28
+ 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.
29
+
30
+ 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).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/calinoi/fusion-client.
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
41
+
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fusion/client"
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(__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,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fusion/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fusion-client"
8
+ spec.version = Fusion::Client::VERSION
9
+ spec.authors = ["Josh Starcher"]
10
+ spec.email = ["josh.starcher@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client for interaction with Callinoi's Fusion API.}
13
+ spec.homepage = "http://www.calinoi.com"
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_dependency('rest-client', '~> 2.0.2')
24
+ spec.add_dependency('activesupport', '>= 2.2.1')
25
+ spec.add_dependency('retryable-rb', '~> 1.1.0')
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "rubocop", "~> 0.49.1"
31
+ end
@@ -0,0 +1,114 @@
1
+ require 'fusion/client/version'
2
+ require 'json'
3
+ require 'active_support/all'
4
+ require 'rest-client'
5
+
6
+ module Fusion
7
+ class Client
8
+ URL = 'https://fusionpro1450.cloudapp.net/FusionProRestService/'
9
+
10
+ class << self
11
+ attr_accessor :username, :password
12
+
13
+ def configure
14
+ yield self
15
+ end
16
+ end
17
+
18
+ def initialize(username: nil, password: nil)
19
+ Fusion::Client.username ||= username
20
+ Fusion::Client.password ||= password
21
+ end
22
+
23
+ def add_job(template:, data:, proof:)
24
+ logon
25
+
26
+ path = "addjob?templatename=#{template}&sessionid=#{@session_id}&bReturnSingleProof=#{proof}"
27
+ params = data
28
+ response = request(:post, params, path)
29
+ response['response']
30
+ end
31
+
32
+ def cancel_job(job_id:)
33
+ logon
34
+
35
+ path = 'canceljob'
36
+ params = { JobID: job_id, SessionID: @session_id }
37
+ request(:post, params, path)
38
+ end
39
+
40
+ def bypass_timer(job_id:)
41
+ logon
42
+
43
+ path = 'bypasstimer'
44
+ params = { JobID: job_id, SessionID: @session_id }
45
+ request(:post, params, path)
46
+ end
47
+
48
+
49
+ def request(method, params, path)
50
+ raise 'You need to configure Fusion::Client with your username and password.' unless Client.username && Client.password
51
+
52
+ path ||= default_path
53
+ url = URL
54
+ url += path
55
+
56
+ if params.is_a?(Hash)
57
+ params = params.to_json
58
+ content_type = 'application/json'
59
+ else
60
+ content_type = 'application/octet-stream'
61
+ end
62
+ RestClient::Request.execute(:method => method, :url => url, payload: params, :headers => {:accept => :json, content_type: content_type}, :timeout => nil, :verify_ssl => false) { |response, request, result, &block|
63
+ handle_response(response, request, result)
64
+ }
65
+ end
66
+
67
+ def handle_response(response, request, result)
68
+ case response.code
69
+ when 200..299
70
+ JSON.parse(response)
71
+ when 400
72
+ raise RestClient::BadRequest, response
73
+ when 404
74
+ raise RestClient::ResourceNotFound, response
75
+ when 500
76
+ raise RestClient::InternalServerError, response
77
+ else
78
+ puts response.inspect
79
+ puts request.inspect
80
+ raise result.to_s
81
+ end
82
+ end
83
+
84
+ def logoff
85
+ return unless @session_id.present?
86
+
87
+ path = 'logoff'
88
+ params = { SessionID: @session_id }
89
+
90
+ begin
91
+ request(:post, params, path)
92
+ rescue => e
93
+ # We don't really care if logoff failed. Log it and move on.
94
+ Rails.logger.debug(e.message)
95
+ end
96
+ end
97
+
98
+ #private
99
+
100
+ def logon
101
+ return if @session_id.present?
102
+
103
+ path = 'logon'
104
+ params = { UserID: Client.username, Password: Client.password }
105
+ response = request(:post, params, path)
106
+ @session_id = response['SessionID']
107
+
108
+ raise response['Message'].inspect unless @session_id.present?
109
+
110
+ response
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,5 @@
1
+ module Fusion
2
+ class Client
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fusion-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Starcher
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: retryable-rb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.49.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.49.1
111
+ description:
112
+ email:
113
+ - josh.starcher@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - fusion-client.gemspec
128
+ - lib/fusion/client.rb
129
+ - lib/fusion/client/version.rb
130
+ homepage: http://www.calinoi.com
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.5.1
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Ruby client for interaction with Callinoi's Fusion API.
154
+ test_files: []