assistly 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +9 -0
  6. data/Gemfile +12 -0
  7. data/HISTORY.mkd +4 -0
  8. data/LICENSE.mkd +20 -0
  9. data/README.mkd +121 -0
  10. data/Rakefile +23 -0
  11. data/assistly.gemspec +43 -0
  12. data/lib/assistly.rb +26 -0
  13. data/lib/assistly/api.rb +23 -0
  14. data/lib/assistly/authentication.rb +25 -0
  15. data/lib/assistly/client.rb +25 -0
  16. data/lib/assistly/client/case.rb +51 -0
  17. data/lib/assistly/client/customer.rb +108 -0
  18. data/lib/assistly/client/interaction.rb +41 -0
  19. data/lib/assistly/client/user.rb +38 -0
  20. data/lib/assistly/client/utils.rb +83 -0
  21. data/lib/assistly/configuration.rb +104 -0
  22. data/lib/assistly/connection.rb +39 -0
  23. data/lib/assistly/error.rb +62 -0
  24. data/lib/assistly/request.rb +44 -0
  25. data/lib/assistly/search.rb +473 -0
  26. data/lib/assistly/version.rb +4 -0
  27. data/lib/faraday/request/multipart_with_file.rb +30 -0
  28. data/lib/faraday/response/raise_http_4xx.rb +45 -0
  29. data/lib/faraday/response/raise_http_5xx.rb +24 -0
  30. data/spec/assistly/api_spec.rb +70 -0
  31. data/spec/assistly/client/case_spec.rb +88 -0
  32. data/spec/assistly/client/customer_spec.rb +158 -0
  33. data/spec/assistly/client/interaction_spec.rb +58 -0
  34. data/spec/assistly/client/user_spec.rb +58 -0
  35. data/spec/assistly/client_spec.rb +10 -0
  36. data/spec/assistly_spec.rb +99 -0
  37. data/spec/faraday/response_spec.rb +34 -0
  38. data/spec/fixtures/case.json +59 -0
  39. data/spec/fixtures/case_update.json +59 -0
  40. data/spec/fixtures/cases.json +182 -0
  41. data/spec/fixtures/customer.json +58 -0
  42. data/spec/fixtures/customer_create.json +56 -0
  43. data/spec/fixtures/customer_create_email.json +15 -0
  44. data/spec/fixtures/customer_update.json +47 -0
  45. data/spec/fixtures/customer_update_email.json +15 -0
  46. data/spec/fixtures/customers.json +98 -0
  47. data/spec/fixtures/interaction_create.json +126 -0
  48. data/spec/fixtures/interactions.json +139 -0
  49. data/spec/fixtures/user.json +15 -0
  50. data/spec/fixtures/users.json +24 -0
  51. data/spec/helper.rb +53 -0
  52. metadata +391 -0
@@ -0,0 +1,58 @@
1
+ require 'helper'
2
+
3
+ describe Assistly::Client do
4
+ Assistly::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = Assistly::Client.new(:subdomain => "example", :format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
8
+ end
9
+
10
+ describe ".user" do
11
+
12
+ context "with id passed" do
13
+
14
+ before do
15
+ stub_get("users/1.#{format}").
16
+ to_return(:body => fixture("user.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
17
+ end
18
+
19
+ it "should get the correct resource" do
20
+ @client.user(1)
21
+ a_get("users/1.#{format}").
22
+ should have_been_made
23
+ end
24
+
25
+ it "should return extended information of a given user" do
26
+ user = @client.user(1)
27
+ user.name.should == "Chris Warren"
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ describe ".users" do
34
+
35
+ context "lookup" do
36
+
37
+ before do
38
+ stub_get("users.#{format}").
39
+ to_return(:body => fixture("users.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
40
+ end
41
+
42
+ it "should get the correct resource" do
43
+ @client.users
44
+ a_get("users.#{format}").
45
+ should have_been_made
46
+ end
47
+
48
+ it "should return up to 100 users worth of extended information" do
49
+ users = @client.users
50
+ users.should be_a Array
51
+ users.first.name.should == "Test User"
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,10 @@
1
+ require 'helper'
2
+
3
+ describe Assistly::Client do
4
+ it "should connect using the endpoint configuration" do
5
+ client = Assistly::Client.new
6
+ endpoint = URI.parse(client.api_endpoint)
7
+ connection = client.send(:connection).build_url(nil).to_s
8
+ connection.should == endpoint.to_s
9
+ end
10
+ end
@@ -0,0 +1,99 @@
1
+ require 'helper'
2
+
3
+ describe Assistly do
4
+ after do
5
+ Assistly.reset
6
+ end
7
+
8
+ # context "when delegating to a client" do
9
+ #
10
+ # before do
11
+ # stub_get("statuses/user_timeline.json").
12
+ # with(:query => {:screen_name => "sferik"}).
13
+ # to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
14
+ # end
15
+ #
16
+ # it "should get the correct resource" do
17
+ # Twitter.user_timeline('sferik')
18
+ # a_get("statuses/user_timeline.json").
19
+ # with(:query => {:screen_name => "sferik"}).
20
+ # should have_been_made
21
+ # end
22
+ #
23
+ # it "should return the same results as a client" do
24
+ # Assistly.user_timeline('sferik').should == Twitter::Client.new.user_timeline('sferik')
25
+ # end
26
+ #
27
+ # end
28
+
29
+ describe ".client" do
30
+ it "should be an Assistly::Client" do
31
+ Assistly.client.should be_a Assistly::Client
32
+ end
33
+ end
34
+
35
+ describe ".adapter" do
36
+ it "should return the default adapter" do
37
+ Assistly.adapter.should == Assistly::Configuration::DEFAULT_ADAPTER
38
+ end
39
+ end
40
+
41
+ describe ".adapter=" do
42
+ it "should set the adapter" do
43
+ Assistly.adapter = :typhoeus
44
+ Assistly.adapter.should == :typhoeus
45
+ end
46
+ end
47
+
48
+ describe ".endpoint" do
49
+ it "should return the default endpoint" do
50
+ Assistly.endpoint.should == Assistly::Configuration::DEFAULT_ENDPOINT
51
+ end
52
+ end
53
+
54
+ describe ".endpoint=" do
55
+ it "should set the endpoint" do
56
+ Assistly.endpoint = 'http://tumblr.com/'
57
+ Assistly.endpoint.should == 'http://tumblr.com/'
58
+ end
59
+ end
60
+
61
+ describe ".format" do
62
+ it "should return the default format" do
63
+ Assistly.format.should == Assistly::Configuration::DEFAULT_FORMAT
64
+ end
65
+ end
66
+
67
+ describe ".format=" do
68
+ it "should set the format" do
69
+ Assistly.format = 'xml'
70
+ Assistly.format.should == 'xml'
71
+ end
72
+ end
73
+
74
+ describe ".user_agent" do
75
+ it "should return the default user agent" do
76
+ Assistly.user_agent.should == Assistly::Configuration::DEFAULT_USER_AGENT
77
+ end
78
+ end
79
+
80
+ describe ".user_agent=" do
81
+ it "should set the user_agent" do
82
+ Assistly.user_agent = 'Custom User Agent'
83
+ Assistly.user_agent.should == 'Custom User Agent'
84
+ end
85
+ end
86
+
87
+ describe ".configure" do
88
+
89
+ Assistly::Configuration::VALID_OPTIONS_KEYS.each do |key|
90
+
91
+ it "should set the #{key}" do
92
+ Assistly.configure do |config|
93
+ config.send("#{key}=", key)
94
+ Assistly.send(key).should == key
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ describe Faraday::Response do
4
+ before do
5
+ @client = Assistly::Client.new
6
+ end
7
+
8
+ {
9
+ 400 => Assistly::BadRequest,
10
+ 401 => Assistly::Unauthorized,
11
+ 403 => Assistly::Forbidden,
12
+ 404 => Assistly::NotFound,
13
+ 406 => Assistly::NotAcceptable,
14
+ 420 => Assistly::EnhanceYourCalm,
15
+ 500 => Assistly::InternalServerError,
16
+ 502 => Assistly::BadGateway,
17
+ 503 => Assistly::ServiceUnavailable,
18
+ }.each do |status, exception|
19
+ context "when HTTP status is #{status}" do
20
+
21
+ before do
22
+ stub_get('users/1.json').
23
+ with(:headers => {'Accept'=>'application/json', 'User-Agent'=>'Assistly Ruby Gem 0.0.1'}).
24
+ to_return(:status => status)
25
+ end
26
+
27
+ it "should raise #{exception.name} error" do
28
+ lambda do
29
+ @client.user(1)
30
+ end.should raise_error(exception)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,59 @@
1
+ {
2
+ "case":
3
+ {
4
+ "id":1,
5
+ "external_id":"123",
6
+ "last_available_at":"2011-02-22T22:30:09Z",
7
+ "created_at":"2011-02-09T17:06:24Z",
8
+ "active_at":"2011-02-22T20:27:31Z",
9
+ "route_at":"2011-02-09T17:06:24Z",
10
+ "first_resolved_at":null,
11
+ "active_user":null,
12
+ "updated_at":"2011-02-22T22:30:09Z",
13
+ "case_status_at":"2011-02-14T17:28:31Z",
14
+ "priority":4,
15
+ "last_saved_by_id":null,
16
+ "interaction_in_at":"2011-02-09T09:06:27Z",
17
+ "assigned_at":"2011-02-09T17:06:24Z",
18
+ "subject":"Welcome to Assistly",
19
+ "routed_at":null,
20
+ "group":
21
+ {
22
+ "id":1,
23
+ "name":"General",
24
+ "created_at":"2011-02-09T17:06:04Z",
25
+ "updated_at":"2011-02-09T17:06:04Z"
26
+ },
27
+ "user":
28
+ {
29
+ "id":1,
30
+ "name":"Joslyn Esser",
31
+ "name_public":"Joslyn Esser",
32
+ "email":"joslyn@example.com",
33
+ "created_at":"2011-02-09T17:02:46Z",
34
+ "updated_at":"2011-02-16T19:25:10Z",
35
+ "user_level":"agent",
36
+ "login_count":15,
37
+ "time_zone":"Pacific Time (US & Canada)",
38
+ "last_login_at":"2011-02-15T23:32:51Z",
39
+ "current_login_at":"2011-02-16T19:25:10Z"
40
+ },
41
+ "first_opened_at":"2011-02-14T17:28:31Z",
42
+ "channel":"email",
43
+ "resolved_at":null,
44
+ "description":null,
45
+ "customer_id":1,
46
+ "closed_at":null,
47
+ "changed_at":"2011-02-14T17:28:31Z",
48
+ "case_status_type":"open",
49
+ "labels":["Example"],
50
+ "pending_at":null,
51
+ "opened_at":"2011-02-14T17:28:31Z",
52
+ "route_status":"available",
53
+ "thread_count":1,
54
+ "note_count":0,
55
+ "preview":"Thanks for trying Assistly. We hope your trial goes well and you decide to use Assistly to wow your customers. Please let us know if there is anything we can do to make your experience better. In the meantime see the tips below for getting started",
56
+ "macros":null,
57
+ "articles":null
58
+ }
59
+ }
@@ -0,0 +1,59 @@
1
+ {
2
+ "case":
3
+ {
4
+ "id":1,
5
+ "external_id":"123",
6
+ "last_available_at":"2011-02-22T22:30:09Z",
7
+ "created_at":"2011-02-09T17:06:24Z",
8
+ "active_at":"2011-02-22T20:27:31Z",
9
+ "route_at":"2011-02-09T17:06:24Z",
10
+ "first_resolved_at":null,
11
+ "active_user":null,
12
+ "updated_at":"2011-02-22T22:30:09Z",
13
+ "case_status_at":"2011-02-14T17:28:31Z",
14
+ "priority":4,
15
+ "last_saved_by_id":null,
16
+ "interaction_in_at":"2011-02-09T09:06:27Z",
17
+ "assigned_at":"2011-02-09T17:06:24Z",
18
+ "subject":"Welcome to Assistly",
19
+ "routed_at":null,
20
+ "group":
21
+ {
22
+ "id":1,
23
+ "name":"General",
24
+ "created_at":"2011-02-09T17:06:04Z",
25
+ "updated_at":"2011-02-09T17:06:04Z"
26
+ },
27
+ "user":
28
+ {
29
+ "id":1,
30
+ "name":"Joslyn Esser",
31
+ "name_public":"Joslyn Esser",
32
+ "email":"joslyn@example.com",
33
+ "created_at":"2011-02-09T17:02:46Z",
34
+ "updated_at":"2011-02-16T19:25:10Z",
35
+ "user_level":"agent",
36
+ "login_count":15,
37
+ "time_zone":"Pacific Time (US & Canada)",
38
+ "last_login_at":"2011-02-15T23:32:51Z",
39
+ "current_login_at":"2011-02-16T19:25:10Z"
40
+ },
41
+ "first_opened_at":"2011-02-14T17:28:31Z",
42
+ "channel":"email",
43
+ "resolved_at":null,
44
+ "description":null,
45
+ "customer_id":1,
46
+ "closed_at":null,
47
+ "changed_at":"2011-02-14T17:28:31Z",
48
+ "case_status_type":"open",
49
+ "labels":["Example"],
50
+ "pending_at":null,
51
+ "opened_at":"2011-02-14T17:28:31Z",
52
+ "route_status":"available",
53
+ "thread_count":1,
54
+ "note_count":0,
55
+ "preview":"Thanks for trying Assistly. We hope your trial goes well and you decide to use Assistly to wow your customers. Please let us know if there is anything we can do to make your experience better. In the meantime see the tips below for getting started",
56
+ "macros":null,
57
+ "articles":null
58
+ }
59
+ }
@@ -0,0 +1,182 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "case":
5
+ {
6
+ "id":1,
7
+ "last_available_at":"2010-05-11T18:44:39Z",
8
+ "created_at":"2009-11-25T15:00:41Z",
9
+ "active_at":"2010-05-11T18:42:53Z",
10
+ "route_at":"2009-11-25T15:00:41Z",
11
+ "first_resolved_at":"2010-03-10T16:31:21Z",
12
+ "active_user":null,
13
+ "updated_at":"2010-05-11T19:35:57Z",
14
+ "case_status_at":"2010-05-11T19:35:57Z",
15
+ "priority":9,
16
+ "last_saved_by_id":1,
17
+ "interaction_in_at":"2009-11-25T15:00:41Z",
18
+ "assigned_at":"2010-03-12T20:01:43Z",
19
+ "subject":"Andr\u00e9 M\u00fcller test",
20
+ "routed_at":null,
21
+ "group":null,
22
+ "user": {
23
+ "id":1,
24
+ "name":"Jeremy Suriel",
25
+ "name_public":"Jeremy Suriel",
26
+ "email":"jeremysuriel+agent1@gmail.com",
27
+ "created_at":"2009-11-25T14:58:39Z",
28
+ "updated_at":"2010-07-19T02:36:21Z",
29
+ "user_level":"sysadmin",
30
+ "login_count":561,
31
+ "time_zone":"Eastern Time (US & Canada)",
32
+ "last_login_at":"2010-07-18T02:06:08Z"
33
+ },
34
+ "first_opened_at":"2010-03-09T15:27:00Z",
35
+ "channel":"chat",
36
+ "resolved_at":"2010-03-10T16:31:21Z",
37
+ "description":"test",
38
+ "customer_id":2,
39
+ "closed_at":"2010-05-11T19:35:57Z",
40
+ "changed_at":"2010-05-11T19:35:57Z",
41
+ "case_status_type":"closed",
42
+ "labels":"test, reload",
43
+ "pending_at":null,
44
+ "opened_at":"2010-03-09T15:27:00Z",
45
+ "route_status":"available",
46
+ "thread_count":1,
47
+ "note_count":1,
48
+ "preview":null,
49
+ "macros":["Example Macros"],
50
+ "articles":["Example Kb Article"],
51
+ "custom_c":"",
52
+ "custom_order":""
53
+ }
54
+ },
55
+ {
56
+ "case":
57
+ {
58
+ "id":2,
59
+ "last_available_at":"2010-03-09T16:08:51Z",
60
+ "created_at":"2009-11-25T15:35:57Z",
61
+ "active_at":"2010-03-09T16:08:43Z",
62
+ "route_at":"2009-11-25T15:35:57Z",
63
+ "first_resolved_at":null,
64
+ "active_user":null,
65
+ "updated_at":"2010-03-18T15:45:34Z",
66
+ "case_status_at":"2010-03-09T16:08:43Z",
67
+ "priority":5,
68
+ "last_saved_by_id":null,
69
+ "interaction_in_at":"2009-11-25T15:35:57Z",
70
+ "assigned_at":null,
71
+ "subject":"test2",
72
+ "routed_at":null,
73
+ "group":null,
74
+ "user":null,
75
+ "first_opened_at":"2010-03-09T16:08:43Z",
76
+ "channel":"twitter",
77
+ "resolved_at":null,
78
+ "description":"test2",
79
+ "customer_id":8,
80
+ "closed_at":null,
81
+ "changed_at":"2010-03-18T15:45:34Z",
82
+ "case_status_type":"open",
83
+ "labels":"",
84
+ "pending_at":null,
85
+ "opened_at":"2010-03-09T16:08:43Z",
86
+ "route_status":"available",
87
+ "thread_count":1,
88
+ "note_count":1,
89
+ "preview":null,
90
+ "macros":null,
91
+ "articles":null,
92
+ "custom_c":null,
93
+ "custom_order":null
94
+ }
95
+ },
96
+ {
97
+ "case":
98
+ {
99
+ "id":3,
100
+ "last_available_at":null,
101
+ "created_at":"2009-11-25T15:35:59Z",
102
+ "active_at":null,
103
+ "route_at":"2009-11-25T15:35:59Z",
104
+ "first_resolved_at":null,
105
+ "active_user":null,
106
+ "updated_at":"2010-03-18T15:45:34Z",
107
+ "case_status_at":"2010-02-23T01:26:59Z",
108
+ "priority":5,
109
+ "last_saved_by_id":1,
110
+ "interaction_in_at":"2009-11-25T15:35:59Z",
111
+ "assigned_at":null,
112
+ "subject":"yo",
113
+ "routed_at":null,
114
+ "group":null,
115
+ "user":null,
116
+ "first_opened_at":"2009-11-26T15:09:01Z",
117
+ "channel":"twitter",
118
+ "resolved_at":null,
119
+ "description":"yo",
120
+ "customer_id":8,
121
+ "closed_at":null,
122
+ "changed_at":"2010-03-18T15:45:34Z",
123
+ "case_status_type":"open",
124
+ "labels":"",
125
+ "pending_at":null,
126
+ "opened_at":"2009-11-26T15:09:01Z",
127
+ "route_status":"available",
128
+ "thread_count":3,
129
+ "note_count":1,
130
+ "preview":"yo",
131
+ "macros":null,
132
+ "articles":null,
133
+ "custom_c":null,
134
+ "custom_order":null
135
+ }
136
+ },
137
+ {
138
+ "case":
139
+ {
140
+ "id":4,
141
+ "last_available_at":null,
142
+ "created_at":"2009-11-25T15:36:01Z",
143
+ "active_at":null,
144
+ "route_at":"2009-11-25T15:36:01Z",
145
+ "first_resolved_at":null,
146
+ "active_user":null,
147
+ "updated_at":"2010-03-18T15:45:34Z",
148
+ "case_status_at":"2010-02-23T01:26:59Z",
149
+ "priority":5,
150
+ "last_saved_by_id":1,
151
+ "interaction_in_at":"2009-11-25T15:36:01Z",
152
+ "assigned_at":null,
153
+ "subject":"Yo yo",
154
+ "routed_at":null,
155
+ "group":null,
156
+ "user":null,
157
+ "first_opened_at":"2009-11-27T17:44:29Z",
158
+ "channel":"twitter",
159
+ "resolved_at":null,
160
+ "description":"Yo yo",
161
+ "customer_id":8,
162
+ "closed_at":null,
163
+ "changed_at":"2010-03-18T15:45:34Z",
164
+ "case_status_type":"open",
165
+ "labels":"",
166
+ "pending_at":null,
167
+ "opened_at":"2009-11-27T17:44:29Z",
168
+ "route_status":"available",
169
+ "thread_count":1,
170
+ "note_count":1,
171
+ "preview":null,
172
+ "macros":null,
173
+ "articles":null,
174
+ "custom_c":null,
175
+ "custom_order":null
176
+ }
177
+ }
178
+ ],
179
+ "page":1,
180
+ "count":4,
181
+ "total":150
182
+ }