freshdesk_apiclient 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b843b0ad25aa39e9d7802c7df8c613f2a3e7460c
|
4
|
+
data.tar.gz: 200cd00955154a5d72cb00be64272fd14f3e29df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90592f93c709aed98ec8c3b7417d2bfdf4dd8316c7819ce9861fa154a06745c0040a198396359cf12092df1da2247115232ec9708181ea650aa5a1d7fb51c8b6
|
7
|
+
data.tar.gz: 114932a708ed8dc2c7c9cb4b2f99649eb276290f5c0cd015f5d664c1998ae25874bb9f6e7963593b4927fdd2ffed11c88010c59b00cdc7ee72660c03d09f8bce
|
@@ -7,22 +7,17 @@ module FreshdeskApiclient
|
|
7
7
|
module REST
|
8
8
|
class Resources
|
9
9
|
def initialize(base_url, options={})
|
10
|
-
@
|
10
|
+
@options = {url: "#{base_url}/#{options[:path] || end_point}"}
|
11
11
|
@headers = headers options[:credentials]
|
12
12
|
RestClient.log = options[:logger]
|
13
13
|
end
|
14
14
|
|
15
15
|
def list
|
16
|
-
|
17
|
-
url: @url,
|
18
|
-
headers: @headers.dup.reject! {|key| [:'Content-Type'].include?(key) })
|
16
|
+
execute(method: :get, headers: @headers.dup.reject! {|key| [:'Content-Type'].include?(key) })
|
19
17
|
end
|
20
18
|
|
21
19
|
def create(json_payload)
|
22
|
-
|
23
|
-
url: @url,
|
24
|
-
headers: @headers,
|
25
|
-
payload: json_payload)
|
20
|
+
execute(method: :post, headers: @headers, payload: json_payload)
|
26
21
|
end
|
27
22
|
|
28
23
|
protected
|
@@ -33,6 +28,10 @@ module FreshdeskApiclient
|
|
33
28
|
|
34
29
|
private
|
35
30
|
|
31
|
+
def execute(options)
|
32
|
+
RestClient::Request.execute @options.merge(options)
|
33
|
+
end
|
34
|
+
|
36
35
|
def headers(credentials)
|
37
36
|
{
|
38
37
|
Authorization: "Basic #{Base64.encode64("#{credentials[:username]}:#{credentials[:password]}")}",
|
data/spec/rest/resources_spec.rb
CHANGED
@@ -7,19 +7,19 @@ RSpec.describe FreshdeskApiclient::REST::Resources do
|
|
7
7
|
RSpec.shared_examples 'a resource' do
|
8
8
|
let(:get_headers) { {Authorization: "Basic dTpw\n", Accept: 'application/json'} }
|
9
9
|
let(:post_headers) { get_headers.merge('Content-Type': 'application/json') }
|
10
|
-
let(:
|
10
|
+
let(:resource) { subject.class.name.split('::').last.downcase }
|
11
11
|
|
12
12
|
describe '#new' do
|
13
13
|
context 'when path option is provided' do
|
14
14
|
subject { FreshdeskApiclient::REST::Resources.new(:url, credentials: {username: :u, password: :p}, path: :foo) }
|
15
15
|
it 'sets the url using given path' do
|
16
|
-
expect(subject.instance_variable_get(:@url)
|
16
|
+
expect(subject.instance_variable_get(:@options)[:url]).to eql("#{:url}/#{:foo}")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'when path option is not provided' do
|
21
21
|
it 'sets the url for the given resource' do
|
22
|
-
expect(subject.instance_variable_get(:@url)
|
22
|
+
expect(subject.instance_variable_get(:@options)[:url]).to eql("#{:url}/#{resource}")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -52,7 +52,7 @@ RSpec.describe FreshdeskApiclient::REST::Resources do
|
|
52
52
|
it('executes the request as a GET') do
|
53
53
|
request = object_double('RestClient::Request', execute: nil).as_stubbed_const
|
54
54
|
subject.list
|
55
|
-
expect(request).to have_received(:execute).with(method: :get, url: "#{:url}/#{
|
55
|
+
expect(request).to have_received(:execute).with(method: :get, url: "#{:url}/#{resource}", headers: get_headers)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -61,7 +61,7 @@ RSpec.describe FreshdeskApiclient::REST::Resources do
|
|
61
61
|
request = object_double('RestClient::Request', execute: nil).as_stubbed_const
|
62
62
|
subject.create :payload
|
63
63
|
expect(request).to have_received(:execute).with(method: :post,
|
64
|
-
url: "#{:url}/#{
|
64
|
+
url: "#{:url}/#{resource}",
|
65
65
|
headers: post_headers,
|
66
66
|
payload: :payload)
|
67
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freshdesk_apiclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erich Quintero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|