zendesk2 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.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in zendesk2.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'guard-rspec'
8
+ gem 'rspec'
9
+ end
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
@@ -0,0 +1,196 @@
1
+ class Zendesk2::Client < Cistern::Service
2
+
3
+ model_path "zendesk2/models"
4
+ request_path "zendesk2/requests"
5
+
6
+ model :organization
7
+ collection :organizations
8
+ model :user
9
+ collection :users
10
+
11
+ request :create_organization
12
+ request :create_user
13
+ request :destroy_organization
14
+ request :destroy_user
15
+ request :get_current_user
16
+ request :get_organization
17
+ request :get_user
18
+ request :get_organizations
19
+ request :get_users
20
+ request :update_organization
21
+ request :update_user
22
+
23
+ recognizes :url, :subdomain, :host, :port, :path, :scheme, :logger, :adapter
24
+
25
+ class Real
26
+
27
+ attr_reader :username, :url
28
+
29
+ def initialize(options={})
30
+ url = options[:url] || begin
31
+ host = options[:host]
32
+ subdomain = options[:subdomain] || Zendesk2.defaults[:subdomain]
33
+
34
+ host ||= "#{subdomain}.zendesk.com"
35
+
36
+ @path = options[:path] || "api/v2"
37
+ scheme = options[:scheme] || "https"
38
+
39
+ port = options[:port] || (scheme == "https" ? 443 : 80)
40
+
41
+ "#{scheme}://#{host}:#{port}/#{@path}"
42
+ end
43
+
44
+ @url = url
45
+ @path ||= URI.parse(url).path
46
+
47
+ logger = options[:logger]
48
+ adapter = options[:adapter] || :net_http
49
+ connection_options = options[:connection_options] || {ssl: {verify: false}}
50
+ @username = options[:username] || Zendesk2.defaults[:username]
51
+ @password = options[:password] || Zendesk2.defaults[:password]
52
+
53
+ raise "Missing required options: [:username, :password]" unless @username && @password
54
+
55
+ @connection = Faraday.new({url: @url}.merge(connection_options)) do |builder|
56
+ # response
57
+ builder.use Faraday::Request::BasicAuthentication, @username, @password
58
+ builder.use Faraday::Response::RaiseError
59
+ builder.use Faraday::Response::Logger, logger if logger
60
+ builder.response :json
61
+
62
+ # request
63
+ builder.request :multipart
64
+ builder.request :json
65
+
66
+ builder.adapter adapter
67
+ end
68
+ end
69
+
70
+ def request(options={})
71
+ method = options[:method] || :get
72
+ url = File.join(@url, options[:path])
73
+ params = options[:params] || {}
74
+ body = options[:body]
75
+ headers = options[:headers] || {}
76
+
77
+ @connection.send(method) do |req|
78
+ req.url url
79
+ req.headers.merge!(headers)
80
+ req.params.merge!(params)
81
+ req.body= body
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ class Mock
88
+ include Zendesk2::Errors
89
+
90
+ attr_reader :username, :url
91
+
92
+ def self.data
93
+ @data ||= {
94
+ :users => {},
95
+ :organizations => {},
96
+ }
97
+ end
98
+
99
+ def self.new_id
100
+ @current_id ||= 0
101
+ @current_id += 1
102
+ end
103
+
104
+ def data
105
+ self.class.data
106
+ end
107
+
108
+ def self.reset!
109
+ @data = nil
110
+ end
111
+
112
+ def initialize(options={})
113
+ url = options[:url] || begin
114
+ host = options[:host]
115
+ host ||= "#{options[:subdomain] || "mock"}.zendesk.com"
116
+
117
+ path = options[:path] || "api/v2"
118
+ scheme = options[:scheme] || "https"
119
+
120
+ port = options[:port] || (scheme == "https" ? 443 : 80)
121
+
122
+ "#{scheme}://#{host}:#{port}/#{path}"
123
+ end
124
+
125
+ @url = url
126
+ @path = URI.parse(url).path
127
+ @username, @password = options[:username], options[:password]
128
+
129
+ @current_user_id = self.class.new_id
130
+
131
+ self.data[:users][@current_user_id]= {
132
+ "id" => @current_user_id,
133
+ "email" => @username,
134
+ "name" => "Mock Agent",
135
+ "url" => url_for("/users/#{@current_user_id}.json"),
136
+ }
137
+ end
138
+
139
+ def url_for(path)
140
+ File.join(@url, path)
141
+ end
142
+
143
+ def page(params, collection, path, collection_root)
144
+ page_params = Zendesk2.paging_parameters(params)
145
+ page_size = (page_params["per_page"] || 50).to_i
146
+ page_index = (page_params["page"] || 1).to_i
147
+ count = self.data[collection].size
148
+ offset = (page_index - 1) * page_size
149
+ total_pages = (count / page_size) + 1
150
+
151
+ next_page = if page_index < total_pages
152
+ url_for("#{path}?page=#{page_index + 1}&per_page=#{page_size}")
153
+ else
154
+ nil
155
+ end
156
+ previous_page = if page_index > 1
157
+ url_for("#{path}?page=#{page_index - 1}&per_page=#{page_size}")
158
+ else
159
+ nil
160
+ end
161
+
162
+ resource_page = self.data[collection].values.slice(offset, page_size)
163
+
164
+ body = {
165
+ collection_root => resource_page,
166
+ "count" => count,
167
+ "next_page" => next_page,
168
+ "previous_page" => previous_page,
169
+ }
170
+
171
+ response(
172
+ body: body,
173
+ path: path
174
+ )
175
+ end
176
+
177
+ def response(options={})
178
+ method = options[:method] || :get
179
+ status = options[:status] || 200
180
+ path = options[:path]
181
+ body = options[:body]
182
+
183
+ url = options[:url] || url_for(path)
184
+
185
+ Faraday::Response.new(
186
+ :method => method,
187
+ :status => status,
188
+ :url => url,
189
+ :body => body,
190
+ :request_headers => {
191
+ "Content-Type" => "application/json"
192
+ },
193
+ )
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,9 @@
1
+ module Zendesk2::Errors
2
+ def not_found
3
+ Faraday::Error::ResourceNotFound
4
+ end
5
+
6
+ def not_found!(*args)
7
+ not_found.new(args)
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ class Zendesk2::Client::Organization < Cistern::Model
2
+ include Zendesk2::Errors
3
+ identity :id
4
+ attribute :shared_comments
5
+ attribute :notes
6
+ attribute :tags
7
+ attribute :domain_names
8
+ attribute :group_id
9
+ attribute :external_id
10
+ attribute :name
11
+ attribute :created_at, type: :time
12
+ attribute :details
13
+ attribute :shared_tickets
14
+ attribute :updated_at, type: :time
15
+
16
+ def save
17
+ if new_record?
18
+ requires :name
19
+ data = connection.create_organization(attributes).body["organization"]
20
+ merge_attributes(data)
21
+ else
22
+ requires :identity
23
+ params = {
24
+ "id" => self.identity,
25
+ "name" => self.name,
26
+ }
27
+ data = connection.update_organization(params).body["organization"]
28
+ merge_attributes(data)
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ requires :identity
34
+
35
+ response = connection.destroy_organization("id" => self.identity)
36
+ end
37
+
38
+ def destroyed?
39
+ self.reload
40
+ rescue not_found
41
+ true
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ class Zendesk2::Client::Organizations < Cistern::Collection
2
+ include Zendesk2::PagedCollection
3
+
4
+ model Zendesk2::Client::Organization
5
+
6
+ self.collection_method= :get_organizations
7
+ self.collection_root= "organizations"
8
+ self.model_method= :get_organization
9
+ self.model_root= "organization"
10
+
11
+ def current
12
+ new(connection.get_current_organization.body["organization"])
13
+ end
14
+
15
+ def search(term)
16
+ body = connection.search_organization("query" => term).body
17
+ if data = body.delete("results")
18
+ load(data)
19
+ end
20
+ merge_attributes(body)
21
+ end
22
+ end
@@ -0,0 +1,60 @@
1
+ class Zendesk2::Client::User < Cistern::Model
2
+ identity :id
3
+ attribute :url
4
+ attribute :external_id
5
+ attribute :name
6
+ attribute :alias
7
+ attribute :created_at, type: :time
8
+ attribute :updated_at, type: :time
9
+ attribute :active, type: :boolean
10
+ attribute :verified, type: :boolean
11
+ attribute :shared
12
+ attribute :locale_id
13
+ attribute :locale
14
+ attribute :time_zone
15
+ attribute :last_login_at, type: :time
16
+ attribute :email
17
+ attribute :phone
18
+ attribute :signature
19
+ attribute :details
20
+ attribute :notes
21
+ attribute :organization_id
22
+ attribute :role
23
+ attribute :custom_role_id
24
+ attribute :moderator
25
+ attribute :ticket_restriction
26
+ attribute :only_private_comments
27
+ attribute :tags
28
+ attribute :suspended
29
+ attribute :photo
30
+ attribute :authenticity_token
31
+
32
+ def save
33
+ if new_record?
34
+ requires :name, :email
35
+ data = connection.create_user(attributes).body["user"]
36
+ merge_attributes(data)
37
+ else
38
+ requires :identity
39
+ params = {
40
+ "id" => self.identity,
41
+ "name" => self.name,
42
+ "email" => self.email,
43
+ }
44
+ data = connection.update_user(params).body["user"]
45
+ merge_attributes(data)
46
+ end
47
+ end
48
+
49
+ def destroy
50
+ requires :identity
51
+ raise "don't nuke yourself" if self.email == connection.username
52
+
53
+ data = connection.destroy_user("id" => self.identity).body["user"]
54
+ merge_attributes(data)
55
+ end
56
+
57
+ def destroyed?
58
+ !self.active
59
+ end
60
+ end
@@ -0,0 +1,22 @@
1
+ class Zendesk2::Client::Users < Cistern::Collection
2
+ include Zendesk2::PagedCollection
3
+
4
+ model Zendesk2::Client::User
5
+
6
+ self.collection_method= :get_users
7
+ self.collection_root= "users"
8
+ self.model_method= :get_user
9
+ self.model_root= "user"
10
+
11
+ def current
12
+ new(connection.get_current_user.body["user"])
13
+ end
14
+
15
+ def search(term)
16
+ body = connection.search_user("query" => term).body
17
+ if data = body.delete("results")
18
+ load(data)
19
+ end
20
+ merge_attributes(body)
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ module Zendesk2::PagedCollection
2
+ def self.included(klass)
3
+ klass.send(:attribute, :count)
4
+ klass.send(:attribute, :next_page_link, {:aliases => "next_page"})
5
+ klass.send(:attribute, :previous_page_link, {:aliases => "previous_page"})
6
+ klass.send(:extend, Zendesk2::PagedCollection::Attributes)
7
+ end
8
+
9
+ def collection_method; self.class.collection_method; end
10
+ def collection_root; self.class.collection_root; end
11
+ def model_method; self.class.model_method; end
12
+ def model_root; self.class.model_root; end
13
+
14
+ def all(params={})
15
+ body = connection.send(collection_method, params).body
16
+
17
+ load(body[collection_root])
18
+ merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
19
+ end
20
+
21
+ def get(id)
22
+ if data = connection.send(model_method, {"id" => id}).body[self.model_root]
23
+ new(data)
24
+ end
25
+ end
26
+
27
+ def next_page
28
+ all("url" => next_page_link) if next_page_link
29
+ end
30
+
31
+ def previous_page
32
+ all("url" => previous_page_link) if previous_page_link
33
+ end
34
+
35
+ module Attributes
36
+ attr_accessor :collection_method, :collection_root, :model_method, :model_root
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_organization(params={})
4
+ request(
5
+ :body => {"organization" => params},
6
+ :method => :post,
7
+ :path => "/organizations.json",
8
+ )
9
+ end
10
+ end # Real
11
+
12
+ class Mock
13
+ def create_organization(params={})
14
+ identity = self.class.new_id
15
+
16
+ record = {
17
+ "id" => identity,
18
+ "url" => url_for("/organizations/#{identity}.json"),
19
+ "created_at" => Time.now.iso8601,
20
+ "updated_at" => Time.now.iso8601,
21
+ }.merge(params)
22
+
23
+ self.data[:organizations][identity]= record
24
+
25
+ response(
26
+ :method => :post,
27
+ :body => {"organization" => record},
28
+ :path => "/organizations.json"
29
+ )
30
+ end
31
+ end # Mock
32
+ end
@@ -0,0 +1,32 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_user(params={})
4
+ request(
5
+ :body => {"user" => params},
6
+ :method => :post,
7
+ :path => "/users.json",
8
+ )
9
+ end
10
+ end # Real
11
+
12
+ class Mock
13
+ def create_user(params={})
14
+ identity = self.class.new_id
15
+
16
+ record = {
17
+ "id" => identity,
18
+ "url" => url_for("/users/#{identity}.json"),
19
+ "created_at" => Time.now.iso8601,
20
+ "updated_at" => Time.now.iso8601,
21
+ }.merge(params)
22
+
23
+ self.data[:users][identity]= record
24
+
25
+ response(
26
+ :method => :post,
27
+ :body => {"user" => record},
28
+ :path => "/users.json"
29
+ )
30
+ end
31
+ end # Mock
32
+ end
@@ -0,0 +1,27 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_organization(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :delete,
8
+ :path => "/organizations/#{id}.json"
9
+ )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def destroy_organization(params={})
15
+ id = params["id"]
16
+ body = self.data[:organizations].delete(id)
17
+
18
+ response(
19
+ :method => :delete,
20
+ :path => "/organizations/#{id}.json",
21
+ :body => {
22
+ "organization" => body,
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_user(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :delete,
8
+ :path => "/users/#{id}.json"
9
+ )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def destroy_user(params={})
15
+ id = params["id"]
16
+ body = self.data[:users].delete(id)
17
+
18
+ response(
19
+ :method => :delete,
20
+ :path => "/users/#{id}.json",
21
+ :body => {
22
+ "user" => body,
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_current_user
4
+ request(
5
+ :method => :get,
6
+ :path => "/users/me.json",
7
+ )
8
+ end
9
+ end # Real
10
+
11
+ class Mock
12
+ def get_current_user
13
+ body = self.data[:users][@current_user_id]
14
+
15
+ response(
16
+ :path => "/users/me.json",
17
+ :body => {
18
+ "user" => body
19
+ },
20
+ )
21
+ end
22
+ end # Mock
23
+ end
@@ -0,0 +1,33 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_organization(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :get,
8
+ :path => "/organizations/#{id}.json"
9
+ )
10
+ end
11
+ end # Real
12
+
13
+ class Mock
14
+ def get_organization(params={})
15
+ id = params["id"]
16
+ if body = self.data[:organizations][id]
17
+
18
+ response(
19
+ :path => "/organizations/#{id}.json",
20
+ :body => {
21
+ "organization" => body
22
+ },
23
+ )
24
+ else
25
+ r = response(
26
+ :path => "/organizations/#{id}.json",
27
+ :status => 404
28
+ )
29
+ raise not_found!(nil, r)
30
+ end
31
+ end
32
+ end # Mock
33
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_organizations(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/organizations.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_organizations(params={})
15
+ page(params, :organizations, "/organizations.json", "organizations")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_user(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :get,
8
+ :path => "/users/#{id}.json"
9
+ )
10
+ end
11
+ end # Real
12
+
13
+ class Mock
14
+ def get_user(params={})
15
+ id = params["id"]
16
+ body = self.data[:users][id]
17
+
18
+ response(
19
+ :path => "/users/#{id}.json",
20
+ :body => {
21
+ "user" => body
22
+ },
23
+ )
24
+ end
25
+ end # Mock
26
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_users(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/users.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_users(params={})
15
+ page(params, :users, "/users.json", "users")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_organization(params={})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/organizations/#{id}.json",
9
+ :body => {
10
+ "organization" => params
11
+ },
12
+ )
13
+ end
14
+ end
15
+ class Mock
16
+ def update_organization(params={})
17
+ id = params.delete("id")
18
+ body = self.data[:organizations][id].merge!(params)
19
+
20
+ response(
21
+ :method => :put,
22
+ :path => "/organizations/#{id}.json",
23
+ :body => {
24
+ "organization" => body
25
+ },
26
+ )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_user(params={})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/users/#{id}.json",
9
+ :body => {
10
+ "user" => params
11
+ },
12
+ )
13
+ end
14
+ end
15
+ class Mock
16
+ def update_user(params={})
17
+ id = params.delete("id")
18
+ body = self.data[:users][id].merge!(params)
19
+
20
+ response(
21
+ :method => :put,
22
+ :path => "/users/#{id}.json",
23
+ :body => {
24
+ "user" => body
25
+ },
26
+ )
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/zendesk2.rb CHANGED
@@ -1,7 +1,38 @@
1
- require "zendesk/version"
1
+ require "zendesk2/version"
2
2
 
3
- module Zendesk
4
- # Your code goes here...
3
+ require 'cistern'
4
+ require 'addressable/uri'
5
+ require 'faraday'
6
+ require 'faraday_middleware'
7
+ require 'uuidtools'
8
+
9
+ require 'time'
10
+
11
+ module Zendesk2
12
+ require 'zendesk2/errors'
13
+ autoload :Client, "zendesk2/client"
14
+ autoload :PagedCollection, "zendesk2/paged_collection"
15
+
16
+ def self.defaults
17
+ @defaults ||= if File.exists?(File.expand_path("~/.zendesk2"))
18
+ YAML.load_file(File.expand_path("~/.zendesk2"))
19
+ else
20
+ {}
21
+ end
22
+ end
23
+
24
+ def self.paging_parameters(options={})
25
+ if url = options["url"]
26
+ uri = Addressable::URI.parse(url)
27
+ uri.query_values
28
+ else
29
+ Cistern::Hash.slice(options, "page", "per_page")
30
+ end
31
+ end
32
+
33
+ def self.uuid
34
+ UUIDTools::UUID.random_create.to_s
35
+ end
5
36
  end
6
37
 
7
- Zendesk2= Zendesk
38
+ Zendesk = Zendesk2
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "organizations" do
4
+ let(:client) { create_client }
5
+ it_should_behave_like "a resource",
6
+ :organizations,
7
+ lambda { {name: Zendesk2.uuid} },
8
+ lambda { {name: Zendesk2.uuid} }
9
+ end
@@ -0,0 +1,50 @@
1
+ shared_examples "a resource" do |_collection, _params, _update_params|
2
+ let(:collection) { client.send(_collection) }
3
+ let(:params) { instance_exec(&_params) || {} }
4
+ let(:update_params) { instance_exec(&_update_params) }
5
+
6
+ it "by creating a record" do
7
+ record = collection.create(params)
8
+ record.identity.should_not be_nil
9
+ end
10
+
11
+ context "that is paged" do
12
+ before(:each) do
13
+ 2.times.each { collection.create(instance_exec(&_params)) }
14
+ end
15
+ it "by retrieving the first page" do
16
+ collection.all("per_page" => "1").size.should == 1
17
+ end
18
+
19
+ it "by retrieving the next page" do
20
+ first_page = collection.all("per_page" => "1").to_a
21
+ second_page = collection.all("per_page" => 1).next_page.to_a
22
+ second_page.should_not == first_page
23
+ end
24
+
25
+ it "by retrieving the previous page" do
26
+ first_page = collection.all("per_page" => "1").to_a
27
+ previous_to_second_page = collection.all("per_page" => 1).next_page.previous_page.to_a
28
+ previous_to_second_page.should == first_page
29
+ end
30
+ end
31
+
32
+ it "by fetching a specific record" do
33
+ record = collection.create(params)
34
+ collection.get(record.identity).should == record
35
+ end
36
+
37
+ it "by updating a record" do
38
+ record = collection.create(params)
39
+ record.merge_attributes(update_params)
40
+ record.save
41
+ update_params.each {|k,v| record.send(k).should == v}
42
+ end
43
+
44
+ it "by destroy a record" do
45
+ record = collection.create(params)
46
+ record.identity.should_not be_nil
47
+ record.destroy
48
+ record.should be_destroyed
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ ENV['MOCK_ZENDESK'] ||= 'true'
2
+
3
+ Bundler.require(:test)
4
+
5
+ require File.expand_path("../../lib/zendesk2", __FILE__)
6
+
7
+ Dir["./spec/{support,shared}/**/*.rb"].each {|f| require f}
8
+
9
+ if ENV["MOCK_ZENDESK"] == 'true'
10
+ Zendesk2::Client.mock!
11
+ end
12
+
13
+ RSpec.configure do |config|
14
+ config.before(:all) do
15
+ Zendesk2::Client.reset! if Zendesk2::Client.mocking?
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'logger'
2
+
3
+ module ClientHelper
4
+ def create_client(options={})
5
+ options.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']
6
+ Zendesk2::Client.new(options)
7
+ end
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+ config.include(ClientHelper)
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "users" do
4
+ let(:client) { create_client }
5
+ it_should_behave_like "a resource",
6
+ :users,
7
+ lambda { {email: "zendesk2+#{Zendesk2.uuid}@example.org", name: "Roger Wilco", verified: true} },
8
+ lambda { {name: "Rogerito Wilcinzo"} }
9
+
10
+ it "should get current user" do
11
+ current_user = client.users.current
12
+ current_user.should be_a(Zendesk2::Client::User)
13
+ current_user.email.should == client.username
14
+ end
15
+ end
data/zendesk2.gemspec CHANGED
@@ -14,4 +14,10 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "zendesk2"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Zendesk2::VERSION
17
+
18
+ gem.add_dependency "cistern", "~> 0.0.2"
19
+ gem.add_dependency "faraday"
20
+ gem.add_dependency "faraday_middleware"
21
+ gem.add_dependency "addressable"
22
+ gem.add_dependency "uuidtools"
17
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,88 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-13 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cistern
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday_middleware
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: addressable
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: uuidtools
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
14
94
  description: Zendesk V2 API client
15
95
  email:
16
96
  - me@joshualane.com
@@ -19,12 +99,37 @@ extensions: []
19
99
  extra_rdoc_files: []
20
100
  files:
21
101
  - .gitignore
102
+ - .rspec
22
103
  - Gemfile
104
+ - Guardfile
23
105
  - LICENSE
24
106
  - README.md
25
107
  - Rakefile
26
108
  - lib/zendesk2.rb
109
+ - lib/zendesk2/client.rb
110
+ - lib/zendesk2/errors.rb
111
+ - lib/zendesk2/models/organization.rb
112
+ - lib/zendesk2/models/organizations.rb
113
+ - lib/zendesk2/models/user.rb
114
+ - lib/zendesk2/models/users.rb
115
+ - lib/zendesk2/paged_collection.rb
116
+ - lib/zendesk2/requests/create_organization.rb
117
+ - lib/zendesk2/requests/create_user.rb
118
+ - lib/zendesk2/requests/destroy_organization.rb
119
+ - lib/zendesk2/requests/destroy_user.rb
120
+ - lib/zendesk2/requests/get_current_user.rb
121
+ - lib/zendesk2/requests/get_organization.rb
122
+ - lib/zendesk2/requests/get_organizations.rb
123
+ - lib/zendesk2/requests/get_user.rb
124
+ - lib/zendesk2/requests/get_users.rb
125
+ - lib/zendesk2/requests/update_organization.rb
126
+ - lib/zendesk2/requests/update_user.rb
27
127
  - lib/zendesk2/version.rb
128
+ - spec/organizations_spec.rb
129
+ - spec/shared/resource.rb
130
+ - spec/spec_helper.rb
131
+ - spec/support/client_helper.rb
132
+ - spec/users_spec.rb
28
133
  - zendesk2.gemspec
29
134
  homepage: ''
30
135
  licenses: []
@@ -50,5 +155,10 @@ rubygems_version: 1.8.24
50
155
  signing_key:
51
156
  specification_version: 3
52
157
  summary: Zendesk V2 API client
53
- test_files: []
158
+ test_files:
159
+ - spec/organizations_spec.rb
160
+ - spec/shared/resource.rb
161
+ - spec/spec_helper.rb
162
+ - spec/support/client_helper.rb
163
+ - spec/users_spec.rb
54
164
  has_rdoc: