octadesk 0.1.1

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
+ SHA256:
3
+ metadata.gz: f178e4b2cddf32c104a03bcb84f031f45ab5716791d7c0d66cd245bef284671c
4
+ data.tar.gz: 476ab1f9e1e86ef212cac227b2a5228ae25b56e283de0a20430ee56f433096f8
5
+ SHA512:
6
+ metadata.gz: fe28f1fe3967d7074e80206bcab785e7215f2c6a86d80cb828f0ffc1e243bac4cf373f27a2dce8b7d73a467f65da60f11f23f1e6c2c51b0950094b578fcf9113
7
+ data.tar.gz: ed003e764bb56c59ca0ad4f3f03b7ee84b4fa2e6a81a9b155be011de40bd86d345eedc1a8b2597816a9cceed4d4a2ebd21179bbf257f9b3dc31a3ab78ab3ef19
data/.gitignore ADDED
@@ -0,0 +1,12 @@
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
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.6
7
+ before_install: gem install bundler -v 1.17.3
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 octadesk.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ octadesk (0.1.0)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ domain_name (0.5.20180417)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-cookie (1.0.3)
14
+ domain_name (~> 0.5)
15
+ mime-types (3.2.2)
16
+ mime-types-data (~> 3.2015)
17
+ mime-types-data (3.2019.0331)
18
+ netrc (0.11.0)
19
+ rake (10.5.0)
20
+ rest-client (2.0.2)
21
+ http-cookie (>= 1.0.2, < 2.0)
22
+ mime-types (>= 1.16, < 4.0)
23
+ netrc (~> 0.8)
24
+ rspec (3.8.0)
25
+ rspec-core (~> 3.8.0)
26
+ rspec-expectations (~> 3.8.0)
27
+ rspec-mocks (~> 3.8.0)
28
+ rspec-core (3.8.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-expectations (3.8.3)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-mocks (3.8.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-support (3.8.0)
37
+ unf (0.1.4)
38
+ unf_ext
39
+ unf_ext (0.0.7.6)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.17)
46
+ octadesk!
47
+ rake (~> 10.0)
48
+ rspec (~> 3.0)
49
+
50
+ BUNDLED WITH
51
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
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,67 @@
1
+ # Octadesk
2
+
3
+ Octadesk gem implements interface to Oficial Octadesk API.
4
+
5
+ ## Requirements
6
+
7
+ You need to account in Octadesk and create API Token, oficial docummentation:
8
+ https://help.octadesk.com/kb/article/como-trabalhar-com-a-api-da-octadesk
9
+
10
+ Rest Client is used to perform all API calls.
11
+
12
+ ## Installation
13
+
14
+ ```ruby
15
+ gem 'octadesk'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install octadesk
25
+
26
+ ## Getting started
27
+
28
+ First need to instance the API:
29
+
30
+ api = Octadesk::Api.new({
31
+ user_email: 'OCTA_USER_EMAIL',
32
+ api_token: 'OCTA_API_TOKEN'
33
+ })
34
+
35
+ ## Methods
36
+
37
+ ##### Generics
38
+
39
+
40
+ * api.get_request("/API_PATH", params={}, headers={})
41
+ -> Returns get from Octa API.
42
+ -> Example: @api.get_request("/persons?email=custumer@email.com")
43
+
44
+ * api.post_request("/API_PATH", params={}, headers={})
45
+ -> Returns post from Octa API.
46
+
47
+ * api.put_request("/API_PATH", params={}, headers={})
48
+ -> Returns put from Octa API.
49
+
50
+ * api.patch_request("/API_PATH", params={}, headers={})
51
+ -> Returns patch from Octa API.
52
+
53
+ * api.head_request("/API_PATH", params={}, headers={})
54
+ -> Returns head from Octa API.
55
+
56
+ * api.delete_request("/API_PATH", params={}, headers={})
57
+ -> Returns delete from Octa API.
58
+
59
+ ## Contributing / Problems?
60
+
61
+ If you have encountered any problem, difficulty or bug, please start by opening a issue.
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/douglaslaraa/octadesk. This project is intended to be a safe, welcoming space for collaboration.
64
+
65
+ ## License
66
+
67
+ 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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "octadesk"
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
data/lib/octadesk.rb ADDED
@@ -0,0 +1,168 @@
1
+ require "octadesk/version"
2
+ require "rest-client"
3
+ require 'ostruct'
4
+ require 'json'
5
+
6
+ module Octadesk
7
+ class Api
8
+ attr_accessor :user_token
9
+
10
+ # Aqui nós recebemos a chave da Api quando o usuário inicializa a nossa classe
11
+ def initialize(args={})
12
+ @user_email = args[:user_email]
13
+ @api_token = args[:api_token]
14
+
15
+ raise ArgumentError if (args[:user_email] == nil or args[:user_email] == "") and (args[:api_token] == nil or args[:api_token] == "")
16
+
17
+ if args[:endpoint_url]
18
+ @endpoint_url = args[:endpoint_url]
19
+ else
20
+ @endpoint_url = 'https://api.octadesk.services'
21
+ end
22
+
23
+ @user_token = get_token(@user_email).body['token']
24
+ #raise ArgumentError if @token == false
25
+ end
26
+
27
+ def get_request(action, params={}, headers={})
28
+ begin
29
+ headers = headers.merge({
30
+ 'accept' => 'application/json',
31
+ 'Content-Type' => 'application/json',
32
+ 'Authorization' => "Bearer #{@user_token}"
33
+ })
34
+
35
+ api_response_kind = headers.delete('api_response_kind')
36
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
37
+ api_response_kind = 'object' if api_response_kind.nil?
38
+
39
+ parse_response(api_response_kind, RestClient.get("#{@endpoint_url}#{action}", {params: params}.merge(headers)))
40
+ rescue => e
41
+ parse_response('object', e.response)
42
+ end
43
+ end
44
+
45
+ def post_request(action, params={}, headers={})
46
+ begin
47
+ headers = headers.merge({
48
+ 'accept' => 'application/json',
49
+ 'Content-Type' => 'application/json',
50
+ 'Authorization' => "Bearer #{@user_token}"
51
+ })
52
+
53
+ api_response_kind = headers.delete('api_response_kind')
54
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
55
+ api_response_kind = 'object' if api_response_kind.nil?
56
+
57
+ parse_response(api_response_kind, RestClient.post("#{@endpoint_url}#{action}", params, headers))
58
+ rescue => e
59
+ parse_response('object', e.response)
60
+ end
61
+ end
62
+
63
+ def put_request(action, params={}, headers={})
64
+ begin
65
+ headers = headers.merge({
66
+ 'accept' => 'application/json',
67
+ 'Content-Type' => 'application/json',
68
+ 'Authorization' => "Bearer #{@user_token}"
69
+ })
70
+
71
+ api_response_kind = headers.delete('api_response_kind')
72
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
73
+ api_response_kind = 'object' if api_response_kind.nil?
74
+
75
+ parse_response(api_response_kind, RestClient.put("#{@endpoint_url}#{action}", params, headers))
76
+ rescue => e
77
+ parse_response('object', e.response)
78
+ end
79
+ end
80
+
81
+ def patch_request(action, params={}, headers={})
82
+ begin
83
+ headers = headers.merge({
84
+ 'accept' => 'application/json',
85
+ 'Content-Type' => 'application/json',
86
+ 'Authorization' => "Bearer #{@user_token}"
87
+ })
88
+
89
+ api_response_kind = headers.delete('api_response_kind')
90
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
91
+ api_response_kind = 'object' if api_response_kind.nil?
92
+
93
+ parse_response(api_response_kind, RestClient.patch("#{@endpoint_url}#{action}", params, headers))
94
+ rescue => e
95
+ parse_response('object', e.response)
96
+ end
97
+ end
98
+
99
+ def head_request(action, params={}, headers={})
100
+ begin
101
+ headers = headers.merge({
102
+ 'accept' => 'application/json',
103
+ 'Content-Type' => 'application/json',
104
+ 'Authorization' => "Bearer #{@user_token}"
105
+ })
106
+
107
+ api_response_kind = headers.delete('api_response_kind')
108
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
109
+ api_response_kind = 'object' if api_response_kind.nil?
110
+
111
+ parse_response(api_response_kind, RestClient.head("#{@endpoint_url}#{action}", params))
112
+ rescue => e
113
+ parse_response('object', e.response)
114
+ end
115
+ end
116
+
117
+ def delete_request(action, params={}, headers={})
118
+ begin
119
+ headers = headers.merge({
120
+ 'accept' => 'application/json',
121
+ 'Content-Type' => 'application/json',
122
+ 'Authorization' => "Bearer #{@user_token}"
123
+ })
124
+
125
+ api_response_kind = headers.delete('api_response_kind')
126
+ api_response_kind = headers.delete(:api_response_kind) if api_response_kind.nil?
127
+ api_response_kind = 'object' if api_response_kind.nil?
128
+
129
+ parse_response(api_response_kind, RestClient.delete("#{@endpoint_url}#{action}", params))
130
+ rescue => e
131
+ parse_response('object', e.response)
132
+ end
133
+ end
134
+
135
+ private
136
+
137
+ def get_token(user_email)
138
+ header = {
139
+ 'accept' => 'application/json',
140
+ 'apiToken' => @api_token,
141
+ 'username' => "#{user_email}".downcase
142
+ }
143
+ request = post_request("/login/apiToken", {}, header )
144
+ request
145
+ end
146
+
147
+ def parse_response(api_response_kind, response)
148
+ result = OpenStruct.new
149
+ result.status_code = response.code
150
+
151
+ if api_response_kind == 'object'
152
+ result.headers = (JSON.parse(response.headers.to_json, object_class: OpenStruct) rescue response.headers)
153
+ result.body = (JSON.parse(response.body, object_class: OpenStruct) rescue response.body)
154
+ elsif api_response_kind == 'hash'
155
+ result.headers = response.headers
156
+ result.body = (JSON.parse(response.body) rescue response.body)
157
+ else
158
+ result.headers = response.headers
159
+ result.body = response.body
160
+ end
161
+
162
+ @last_result = result
163
+
164
+ result
165
+ end
166
+
167
+ end
168
+ end
@@ -0,0 +1,3 @@
1
+ module Octadesk
2
+ VERSION2 = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ module Octadesk
2
+ VERSION = "0.1.1"
3
+ end
data/octadesk.gemspec ADDED
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "octadesk/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "octadesk"
8
+ spec.version = Octadesk::VERSION
9
+ spec.authors = ["Douglas Lara"]
10
+ spec.email = ["douglasdelaras@gmail.com"]
11
+
12
+ spec.summary = %q{Inteface to connect Octadesk API.}
13
+ spec.description = %q{Inteface to connect Octadesk API.}
14
+ spec.homepage = "https://github.com/douglaslaraa/octadesk"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/douglaslaraa/octadesk"
23
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+
42
+ spec.add_runtime_dependency "rest-client", "~> 2.0.2"
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octadesk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Douglas Lara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-28 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.2
69
+ description: Inteface to connect Octadesk API.
70
+ email:
71
+ - douglasdelaras@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/octadesk.rb
87
+ - lib/octadesk/api.rb
88
+ - lib/octadesk/version.rb
89
+ - octadesk.gemspec
90
+ homepage: https://github.com/douglaslaraa/octadesk
91
+ licenses:
92
+ - MIT
93
+ metadata:
94
+ homepage_uri: https://github.com/douglaslaraa/octadesk
95
+ source_code_uri: https://github.com/douglaslaraa/octadesk
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Inteface to connect Octadesk API.
115
+ test_files: []