freshdesk-rest 0.0.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: c4dba7609ed11098e454c7df3efed04ce87562d4dd155a41f0cb3fe61132c8bc
4
+ data.tar.gz: c5a1782f15f2a4d6d9d843dfd32a32f8bc2c3033aab4b633835f7645344aad4d
5
+ SHA512:
6
+ metadata.gz: 54824fb46ebf235ecfbd4bd9a9b29e4a40f149a7f4e5515cbe1671ad87e9879e819a21c6b17c1f4c1fc56abf37d3ab8bc5203a3b0aa0f29f11b7f432edefa511
7
+ data.tar.gz: e262751269bdbfa9eedc23faf475089b53a05e40292d913ce9ce2c0a1eb682ae649070a90366e515210f5e687e5d953bb51e2ff6ab647824d6f6060ae22d303c
@@ -0,0 +1,20 @@
1
+ require_relative 'freshdesk-rest/factory'
2
+ require_relative 'freshdesk-rest/version'
3
+ require_relative 'freshdesk-rest/configuration'
4
+ require_relative 'freshdesk-rest/resource/contact'
5
+
6
+ module Freshdesk
7
+ module Rest
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.reset
13
+ @configuration = Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield(configuration)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,41 @@
1
+ module Freshdesk
2
+ module Rest
3
+ class Api
4
+ def initialize(rest_client:, api_key:, domain:)
5
+ @client = rest_client
6
+ @api_key = api_key
7
+ @domain = domain
8
+ end
9
+
10
+ def get(path)
11
+ resource(path).get.body
12
+ rescue @client::ExceptionWithResponse => e
13
+ return '[]' if e.response.code == 404
14
+ raise e
15
+ end
16
+
17
+ def post(path, data)
18
+ resource(path).post(data.to_json, content_type: 'application/json').body
19
+ end
20
+
21
+ def put(path, data)
22
+ resource(path).put(data.to_json, content_type: 'application/json').body
23
+ end
24
+
25
+ def delete(path)
26
+ resource(path).delete.body
27
+ '{}'
28
+ end
29
+
30
+ private
31
+
32
+ def resource(path)
33
+ @client::Resource.new([base_url, path].join, @api_key, 'X')
34
+ end
35
+
36
+ def base_url
37
+ @base_url ||= "https://#{@domain}.freshdesk.com/api/v2".freeze
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ module Freshdesk
2
+ module Rest
3
+ class Configuration
4
+ attr_writer :api_key, :domain
5
+
6
+ def initialize
7
+ @api_key = nil
8
+ @domain = nil
9
+ end
10
+
11
+ def api_key
12
+ raise 'Freshdesk API key not defined' if @api_key.nil?
13
+ @api_key
14
+ end
15
+
16
+ def domain
17
+ raise 'Freshdesk domain not defined' if @domain.nil?
18
+ @domain
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'rest-client'
2
+ require_relative 'api'
3
+
4
+ module Freshdesk
5
+ module Rest
6
+ class Factory
7
+ def self.api
8
+ Freshdesk::Rest::Api.new(
9
+ rest_client: RestClient,
10
+ api_key: Freshdesk::Rest.configuration.api_key,
11
+ domain: Freshdesk::Rest.configuration.domain
12
+ )
13
+ end
14
+
15
+ def self.contact_resource
16
+ Freshdesk::Rest::Resource::Contact.new(client: api)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'parser'
2
+
3
+ module Freshdesk
4
+ module Rest
5
+ module Resource
6
+ class Contact
7
+ def initialize(client:)
8
+ @client = client
9
+ @path = '/contacts'
10
+ end
11
+
12
+ def list(params: {})
13
+ query = URI.encode_www_form(params.to_a)
14
+ path = [@path, (query.empty? ? nil : query)].compact.join('?')
15
+ Parser.parse(@client.get(path))
16
+ end
17
+
18
+ def get(id:)
19
+ Parser.parse(@client.get("#{@path}/#{id}"))
20
+ end
21
+
22
+ def post(data:)
23
+ Parser.parse(@client.post(@path, data))
24
+ end
25
+
26
+ def put(id:, data:)
27
+ Parser.parse(@client.put("#{@path}/#{id}", data))
28
+ end
29
+
30
+ def delete(id:)
31
+ Parser.parse(@client.delete("#{@path}/#{id}"))
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ module Freshdesk
4
+ module Rest
5
+ module Resource
6
+ module Parser
7
+ OPTIONS = { max_nesting: 4, symbolize_names: true }.freeze
8
+
9
+ def self.parse(json)
10
+ JSON.parse(json, OPTIONS)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Freshdesk
2
+ module Rest
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freshdesk-rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paweł Placzyński
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A ruby gem to interact with Freshdesk REST resources
14
+ email: placzynski.pawel@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/freshdesk-rest.rb
20
+ - lib/freshdesk-rest/api.rb
21
+ - lib/freshdesk-rest/configuration.rb
22
+ - lib/freshdesk-rest/factory.rb
23
+ - lib/freshdesk-rest/resource/contact.rb
24
+ - lib/freshdesk-rest/resource/parser.rb
25
+ - lib/freshdesk-rest/version.rb
26
+ homepage: https://rubygems.org/gems/freshdesk-rest
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ source_code_uri: https://github.com/placek/freshdesk-rest
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.7.3
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Freshdesk rest api resource collection
51
+ test_files: []