desk_api_v2 0.0.1 → 0.0.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2JlYzYyMDg5NzcwZWRhMjc3M2JmZDY5OTkyNDBkNGZhN2UyMzk5ZQ==
4
+ NDUzZTQwZDBkMWI0NzkzMjg0ZjYwZGNiMDdhZTI1MTI0YjhkNGE1Mg==
5
5
  data.tar.gz: !binary |-
6
- YWU0Yzk0YzhiZWQ0MDUyN2Q3MTk5NzczMDJjNjgzNDJjMzJmNjA2Ng==
6
+ YzgzYmZmNjQyNDVjOThjYjE5YWYyYjVhZWRiNjNhOGY4OGYwMmM5OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjhjYjg1MDA0YTE2Y2NjMTZlNmQ5NTk0M2ZkMTJmYjE1ZjYxYjMxYjVjNWNm
10
- MzhjNGRkOGVjZWFhMGRmNzY4NzY3MDM0N2JkMjFkNTc3NDBkYTc1ODBiNDUx
11
- NTkzOTIyMzJiMGQzZTc5N2YxMTA5YzIxMTAwOGMzNDMxOTVmYjY=
9
+ NzBhNGI0M2UxZWY1ZjJmNGYzODA4OGJlYzdmYmQ2MmFhZWE5NWFjYmNiNGM5
10
+ ODg2NWIyY2Y5NTc0MmQyNDBkYTgxYzkwMGM1ZThhNzQxMTZhNjA2Yzk4MjNm
11
+ OTVkMzY4ZjZkOTYxYTU2NjQyYmFkMWEyYWRkODhlZGI4ZTM4MGU=
12
12
  data.tar.gz: !binary |-
13
- YTI1OGQzZTQ1OWYzZjFiZDgwNWY5MjlhNGZjYTEyNjllYzUyNzM0MDE0NDA1
14
- MmNlMTQyODcwNTkyZDEyNGU5YWM2ODMzODYxZjEwMjA5OGY3MzQzYjE5ODU0
15
- MWUxMzNmZThmNzU3ZTc4NGVjZWVkMTNkN2ZkNjcwOTZhOGQ2NTU=
13
+ OTM0M2MyZDAwNmQ2NTNmN2VjOGFiOWY2ZmVmYWI3ZTBhMDU4NWJiYzhiODkz
14
+ MDdiMGQ2MDA3YmNiMTZhMGZjMWVjNjQwMDc1NzNhOTQ2M2JlY2Y2NWVhNGI2
15
+ MWIxZGMzNjk1ZmZhMDcxMjliNWVmMGZlNmQ0ZWIwZGE4YWYyNGE=
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- Gemfile.lock
1
+ Gemfile.lock
2
+ *.gem
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rake/testtask'
2
+ require 'bump/tasks'
2
3
 
3
4
  begin
4
5
  require "bundler"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "desk_api_v2"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Justin Powers"]
6
6
  s.email = ["justinspowers@gmail.com"]
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "webmock", "~> 1.11.0"
25
25
  s.add_development_dependency "minitest", "~> 3.5.0"
26
26
  s.add_development_dependency "minitest-reporters", "~> 0.14.20"
27
+ s.add_development_dependency "bump"
27
28
  end
@@ -9,3 +9,5 @@ require 'desk/customer'
9
9
  require 'desk/topic'
10
10
  require 'desk/group'
11
11
  require 'desk/filter'
12
+ require 'desk/brand'
13
+ require 'desk/company'
@@ -0,0 +1,19 @@
1
+ require 'desk/api/modules/listable'
2
+ require 'desk/brand'
3
+
4
+ module Desk
5
+ module Api
6
+ class Brands
7
+
8
+ include Desk::Api::Listable
9
+
10
+ attr_reader :connection, :endpoint, :return_class
11
+
12
+ def initialize(connection)
13
+ @connection = connection
14
+ @endpoint = "brands"
15
+ @return_class = Desk::Brand
16
+ end
17
+ end
18
+ end
19
+ end
@@ -19,7 +19,7 @@ module Desk
19
19
  :assigned_user, :channels, :notes, :attachments,
20
20
  :case_custom_key, :created, :updated, :since_created_at,
21
21
  :max_created_at, :since_updated_at, :max_updated_at,
22
- :since_id, :max_id]
22
+ :since_id, :max_id, :q]
23
23
 
24
24
  attr_reader :connection, :endpoint, :return_class
25
25
 
@@ -0,0 +1,36 @@
1
+ # require 'active_support/core_ext/hash'
2
+ require 'desk/api/modules/listable'
3
+ require 'desk/api/modules/creatable'
4
+ require 'desk/api/modules/searchable'
5
+ require 'desk/company'
6
+
7
+ module Desk
8
+ module Api
9
+ class Companies
10
+
11
+ include Desk::Api::Listable
12
+ include Desk::Api::Creatable
13
+ include Desk::Api::Searchable
14
+
15
+ VALID_SEARCH_PARAMS= [:q]
16
+
17
+ attr_reader :connection, :endpoint, :return_class
18
+
19
+ def initialize(connection)
20
+ @connection = connection
21
+ @endpoint = "companies"
22
+ @return_class = Desk::Company
23
+ end
24
+
25
+ def cases(id)
26
+ Desk::Collection.new(connection.get("companies/#{id}/cases"), Desk::Case)
27
+ end
28
+
29
+ private
30
+
31
+ def valid_search_params
32
+ VALID_SEARCH_PARAMS
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'desk/entity'
2
+
3
+ module Desk
4
+ class Brand < Entity
5
+
6
+ end
7
+ end
@@ -5,6 +5,8 @@ require 'desk/api/translations'
5
5
  require 'desk/api/customers'
6
6
  require 'desk/api/topics'
7
7
  require 'desk/api/groups'
8
+ require 'desk/api/brands'
9
+ require 'desk/api/companies'
8
10
 
9
11
  module Desk
10
12
  class Client
@@ -29,6 +31,14 @@ module Desk
29
31
  Desk::Api::Topics.new(connection)
30
32
  end
31
33
 
34
+ def brands
35
+ Desk::Api::Brands.new(connection)
36
+ end
37
+
38
+ def companies
39
+ Desk::Api::Brands.new(connection)
40
+ end
41
+
32
42
  private
33
43
 
34
44
  def connection
@@ -0,0 +1,7 @@
1
+ require 'desk/entity'
2
+
3
+ module Desk
4
+ class Company < Entity
5
+
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ module MiniTest::Assertions
2
+
3
+ def assert_connects_to_endpoint(endpoint, opts={})
4
+ fixture = opts[:fixture]
5
+ method = opts[:method] || :get
6
+
7
+ @connection.expect(method, fixture, [endpoint])
8
+ @result = yield
9
+ @connection.verify
10
+ end
11
+
12
+ def assert_returns_array_of(obj_class, opts={}, &blk)
13
+ assert_connects_to_endpoint(opts[:endpoint], fixture: opts[:fixture], &blk)
14
+
15
+ assert @result.is_a? Array
16
+ assert @result.first.is_a? obj_class
17
+ end
18
+
19
+ def assert_returns_one_of(obj_class, opts={}, &blk)
20
+ assert_connects_to_endpoint(opts[:endpoint], fixture: opts[:fixture], &blk)
21
+
22
+ assert @result.is_a? obj_class
23
+
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+ require_relative '../../spec_helper'
3
+
4
+ class BrandsSpec
5
+ describe Desk::Api::Brands do
6
+
7
+ before { @connection = Minitest::Mock.new }
8
+
9
+ subject { Desk::Api::Brands.new(@connection) }
10
+
11
+ describe "#all" do
12
+
13
+ it "will return an array of brands" do
14
+ assert_returns_array_of(Desk::Brand, endpoint: "brands", fixture: brands_fixture) { subject.all }
15
+ end
16
+ end
17
+
18
+ describe "#show" do
19
+ it "will return a single brand object" do
20
+ assert_returns_one_of(Desk::Brand, endpoint: "brands/1234", fixture: brand_fixture) { subject.show(1234) }
21
+ end
22
+ end
23
+
24
+ def brands_fixture
25
+ JSON.load(fixture("brands.json"))
26
+ end
27
+
28
+ def brand_fixture
29
+ JSON.load(fixture("brand.json"))
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,97 @@
1
+ require 'json'
2
+ require_relative '../../spec_helper'
3
+
4
+ class CompaniesSpec
5
+ describe Desk::Api::Companies do
6
+
7
+ before { @connection = Minitest::Mock.new }
8
+
9
+ subject { Desk::Api::Companies.new(@connection) }
10
+
11
+ describe "#all" do
12
+
13
+ it "will return an array of brands" do
14
+ assert_returns_array_of(Desk::Company, endpoint: "companies", fixture: companies_fixture) { subject.all }
15
+ end
16
+ end
17
+
18
+ describe "#show" do
19
+ it "will return a single company object" do
20
+ assert_returns_one_of(Desk::Company, endpoint: "companies/1234", fixture: company_fixture) { subject.show(1234) }
21
+ end
22
+ end
23
+
24
+ describe "#create" do
25
+
26
+ before do
27
+ @connection.expect(:post, company_fixture, ["companies", company_create_fixture])
28
+ end
29
+
30
+ it "will connect to the case creation endpoint" do
31
+ subject.create(company_create_fixture)
32
+
33
+ @connection.verify
34
+ end
35
+ end
36
+
37
+ describe "#update" do
38
+ before do
39
+ @connection.expect(:patch, company_fixture, ["companies/1234", company_update_fixture])
40
+ end
41
+
42
+ it "will connect to the case update endpoint" do
43
+ subject.update(1234, company_update_fixture)
44
+
45
+ @connection.verify
46
+ end
47
+ end
48
+
49
+ describe "#search" do
50
+
51
+ it "will pass whitelisted params into the search query" do
52
+ @connection.expect(:get, companies_fixture, ["companies/search", {q: "foo"}])
53
+
54
+ subject.search(q: "foo")
55
+
56
+ @connection.verify
57
+ end
58
+
59
+ it "will whitelist hash arguments" do
60
+ @connection.expect(:get, companies_fixture, ["companies/search", {q: "foo"}])
61
+
62
+ subject.search(q: "foo", bar: "baz")
63
+
64
+ @connection.verify
65
+ end
66
+ end
67
+
68
+ describe "#cases" do
69
+
70
+ before { @connection.expect(:get, cases_fixture, ["companies/1234/cases"]) }
71
+
72
+ it "will return an array of cases" do
73
+ assert_returns_array_of(Desk::Case, endpoint: "companies/1234/cases", fixture: cases_fixture) { subject.cases(1234) }
74
+ end
75
+ end
76
+
77
+ def companies_fixture
78
+ JSON.load(fixture("companies.json"))
79
+ end
80
+
81
+ def company_fixture
82
+ JSON.load(fixture("company.json"))
83
+ end
84
+
85
+ def company_create_fixture
86
+ JSON.load(fixture("company_create.json"))
87
+ end
88
+
89
+ def company_update_fixture
90
+ JSON.load(fixture("company_update.json"))
91
+ end
92
+
93
+ def cases_fixture
94
+ JSON.load(fixture("cases.json"))
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "Desk.com",
3
+ "created_at": "2014-01-20T21:33:58Z",
4
+ "updated_at": "2014-01-20T21:33:58Z",
5
+ "_links": {
6
+ "self": {
7
+ "href": "/api/v2/brands/1",
8
+ "class": "brand"
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "total_entries": 2,
3
+ "_links": {
4
+ "self": {
5
+ "href": "/api/v2/brands?page=1&per_page=50",
6
+ "class": "page"
7
+ },
8
+ "first": {
9
+ "href": "/api/v2/brands?page=1&per_page=50",
10
+ "class": "page"
11
+ },
12
+ "last": {
13
+ "href": "/api/v2/brands?page=1&per_page=50",
14
+ "class": "page"
15
+ },
16
+ "next": null,
17
+ "previous": null
18
+ },
19
+ "_embedded": {
20
+ "entries": [
21
+ {
22
+ "name": "Desk.com",
23
+ "created_at": "2014-01-20T21:33:58Z",
24
+ "updated_at": "2014-01-20T21:33:58Z",
25
+ "_links": {
26
+ "self": {
27
+ "href": "/api/v2/brands/1",
28
+ "class": "brand"
29
+ }
30
+ }
31
+ },
32
+ {
33
+ "name": "Alpha Inc",
34
+ "created_at": "2014-01-20T21:33:58Z",
35
+ "updated_at": "2014-01-20T21:33:58Z",
36
+ "_links": {
37
+ "self": {
38
+ "href": "/api/v2/brands/2",
39
+ "class": "brand"
40
+ }
41
+ }
42
+ }
43
+ ]
44
+ }
45
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "total_entries": 2,
3
+ "_links": {
4
+ "self": {
5
+ "href": "/api/v2/companies?page=1&per_page=50",
6
+ "class": "page"
7
+ },
8
+ "first": {
9
+ "href": "/api/v2/companies?page=1&per_page=50",
10
+ "class": "page"
11
+ },
12
+ "last": {
13
+ "href": "/api/v2/companies?page=1&per_page=50",
14
+ "class": "page"
15
+ },
16
+ "next": null,
17
+ "previous": null
18
+ },
19
+ "_embedded": {
20
+ "entries": [
21
+ {
22
+ "name": "Acme Inc",
23
+ "domains": [
24
+ "acmeinc.com",
25
+ "acmeinc.net"
26
+ ],
27
+ "created_at": "2014-01-21T21:10:53Z",
28
+ "updated_at": "2014-01-21T21:10:53Z",
29
+ "custom_fields": {
30
+ "employer_id": "123456789"
31
+ },
32
+ "_links": {
33
+ "self": {
34
+ "href": "/api/v2/companies/1",
35
+ "class": "company"
36
+ },
37
+ "customers": {
38
+ "href": "/api/v2/companies/1/customers",
39
+ "class": "customer"
40
+ },
41
+ "cases": {
42
+ "href": "/api/v2/companies/1/cases",
43
+ "class": "case"
44
+ }
45
+ }
46
+ },
47
+ {
48
+ "name": "Desk.com",
49
+ "domains": [
50
+ "desk.com",
51
+ "salesforce.com"
52
+ ],
53
+ "created_at": "2014-01-21T21:10:53Z",
54
+ "updated_at": "2014-01-21T21:10:53Z",
55
+ "custom_fields": {
56
+ "employer_id": "123456789"
57
+ },
58
+ "_links": {
59
+ "self": {
60
+ "href": "/api/v2/companies/2",
61
+ "class": "company"
62
+ },
63
+ "customers": {
64
+ "href": "/api/v2/companies/2/customers",
65
+ "class": "customer"
66
+ },
67
+ "cases": {
68
+ "href": "/api/v2/companies/2/cases",
69
+ "class": "case"
70
+ }
71
+ }
72
+ }
73
+ ]
74
+ }
75
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "Acme Inc",
3
+ "domains": [
4
+ "acmeinc.com",
5
+ "acmeinc.net"
6
+ ],
7
+ "created_at": "2014-01-21T21:10:53Z",
8
+ "updated_at": "2014-01-21T21:10:53Z",
9
+ "custom_fields": {
10
+ "employer_id": "123456789"
11
+ },
12
+ "_links": {
13
+ "self": {
14
+ "href": "/api/v2/companies/1",
15
+ "class": "company"
16
+ },
17
+ "customers": {
18
+ "href": "/api/v2/companies/1/customers",
19
+ "class": "customer"
20
+ },
21
+ "cases": {
22
+ "href": "/api/v2/companies/1/cases",
23
+ "class": "case"
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "Acme Inc",
3
+ "domains": [
4
+ "acmeinc.com",
5
+ "acmeinc.net"
6
+ ],
7
+ "custom_fields": {
8
+ "employer_id": "123456789"
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "Acme Enterprises",
3
+ "domains": [
4
+ "acme-ent.com",
5
+ "acmeinc.com",
6
+ "acmeinc.net"
7
+ ],
8
+ "custom_fields": {
9
+ "employer_id": "987654321"
10
+ }
11
+ }
@@ -6,6 +6,8 @@ require 'minitest/autorun'
6
6
  require 'minitest/reporters'
7
7
  require 'webmock/minitest'
8
8
 
9
+ require_relative 'assertions'
10
+
9
11
  MiniTest::Reporters.use!
10
12
 
11
13
  def fixture_path
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desk_api_v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Powers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.14.20
111
+ - !ruby/object:Gem::Dependency
112
+ name: bump
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A ruby interface to the Desk.com API V2
112
126
  email:
113
127
  - justinspowers@gmail.com
@@ -124,7 +138,9 @@ files:
124
138
  - desk_api_v2.gemspec
125
139
  - lib/desk.rb
126
140
  - lib/desk/api/articles.rb
141
+ - lib/desk/api/brands.rb
127
142
  - lib/desk/api/cases.rb
143
+ - lib/desk/api/companies.rb
128
144
  - lib/desk/api/customers.rb
129
145
  - lib/desk/api/groups.rb
130
146
  - lib/desk/api/modules/creatable.rb
@@ -134,9 +150,11 @@ files:
134
150
  - lib/desk/api/topics.rb
135
151
  - lib/desk/api/translations.rb
136
152
  - lib/desk/article.rb
153
+ - lib/desk/brand.rb
137
154
  - lib/desk/case.rb
138
155
  - lib/desk/client.rb
139
156
  - lib/desk/collection.rb
157
+ - lib/desk/company.rb
140
158
  - lib/desk/connection.rb
141
159
  - lib/desk/customer.rb
142
160
  - lib/desk/entity.rb
@@ -148,8 +166,11 @@ files:
148
166
  - lib/desk/topic.rb
149
167
  - lib/desk/translation.rb
150
168
  - lib/desk/user.rb
169
+ - spec/assertions.rb
151
170
  - spec/desk/api/articles_spec.rb
171
+ - spec/desk/api/brands_spec.rb
152
172
  - spec/desk/api/cases_spec.rb
173
+ - spec/desk/api/companies_spec.rb
153
174
  - spec/desk/api/customers_spec.rb
154
175
  - spec/desk/api/groups_spec.rb
155
176
  - spec/desk/api/topics_spec.rb
@@ -158,8 +179,14 @@ files:
158
179
  - spec/desk/connection_spec.rb
159
180
  - spec/fixtures/article.json
160
181
  - spec/fixtures/articles.json
182
+ - spec/fixtures/brand.json
183
+ - spec/fixtures/brands.json
161
184
  - spec/fixtures/case.json
162
185
  - spec/fixtures/cases.json
186
+ - spec/fixtures/companies.json
187
+ - spec/fixtures/company.json
188
+ - spec/fixtures/company_create.json
189
+ - spec/fixtures/company_update.json
163
190
  - spec/fixtures/customer.json
164
191
  - spec/fixtures/customers.json
165
192
  - spec/fixtures/group.json