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: 4c1325f27dbe6b78e075ca30e6bd13eac3ce703c
4
- data.tar.gz: 5083628601c39740f5541df1cb37bf63fba26ddc
3
+ metadata.gz: b843b0ad25aa39e9d7802c7df8c613f2a3e7460c
4
+ data.tar.gz: 200cd00955154a5d72cb00be64272fd14f3e29df
5
5
  SHA512:
6
- metadata.gz: 3ef19caa813097a04bc01c2615e9dc1cc21d7810772a1184faee30ea3c2af5dcbe20c0e7458d9266e3c4df3a9bbe31b8e61e6ca52242869ecb0ae635b27f24fc
7
- data.tar.gz: d11d2ca82bd1e7d2a856b0f3cca693b80429eda9bd8ff0ce285d2ab08c52ded326ef417555af03d703b1eb20079ad0309a416867cb0dbc9383225707c15450af
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
- @url = "#{base_url}/#{options[:path] || end_point}"
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
- RestClient::Request.execute(method: :get,
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
- RestClient::Request.execute(method: :post,
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]}")}",
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module FreshdeskApiclient
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
@@ -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(:path) { subject.class.name.split('::').last.downcase }
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)).to eql("#{:url}/#{:foo}")
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)).to eql("#{:url}/#{path}")
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}/#{path}", headers: get_headers)
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}/#{path}",
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.0
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-02-28 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client