assistly 0.1

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.
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
File without changes
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .bundle
5
+ .rvmrc
6
+ .yardoc
7
+ Gemfile.lock
8
+ coverage/*
9
+ doc/*
10
+ log/*
11
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.1
4
+ - 1.9.2
5
+ - jruby
6
+ - rbx
7
+ - ree
@@ -0,0 +1,9 @@
1
+ --no-private
2
+ --protected
3
+ --tag format:"Supported formats"
4
+ --tag authenticated:"Requires Authentication"
5
+ --tag rate_limited:"Rate Limited"
6
+ --markup markdown
7
+ -
8
+ HISTORY.mkd
9
+ LICENSE.mkd
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+
6
+ group :development do
7
+ gem "ruby-debug"
8
+ end
9
+
10
+ group :test do
11
+ gem "ruby-debug"
12
+ end
@@ -0,0 +1,4 @@
1
+ 0.1 - April 12, 2011
2
+ -------------------------
3
+ * Initial release
4
+ * Support for Case, Customer, Interaction, and User APIs.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Chris Warren
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,121 @@
1
+ The Assistly Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the Assistly API
4
+
5
+ Installation
6
+ ------------
7
+ gem install assistly
8
+
9
+ What's new in 0.1?
10
+ ------------------
11
+ This is the first release of the Assistly gem, based on the [Twitter gem](http://github.com/jnunemaker/twitter). Support for most of the [Assistly API](http://dev.assistly.com/docs/api) are handled.
12
+ There is not yet support for Content or Macros.
13
+
14
+ Help! I'm getting: "Did not recognize your engine specification. Please specify either a symbol or a class. (RuntimeError)"
15
+ ---------------------------------------------------------------------------------------------------------------------------
16
+
17
+ You'll need to explicitly require a JSON library. We recommend [yajl-ruby](http://github.com/brianmario/yajl-ruby).
18
+
19
+ Usage Examples
20
+ --------------
21
+ require "rubygems"
22
+ require "assistly"
23
+
24
+ # All methods require authentication. To get your Assistly OAuth credentials,
25
+ # register an app in the Assistly admin for your account at http://your-domain.assistly.com/admin
26
+ @assistly = Assistly.configure do |config|
27
+ config.consumer_key = YOUR_CONSUMER_KEY
28
+ config.consumer_secret = YOUR_CONSUMER_SECRET
29
+ config.oauth_token = YOUR_OAUTH_TOKEN
30
+ config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
31
+ end
32
+
33
+ # List cases
34
+ @assistly.cases
35
+ @assistly.cases(:since_id => 12345)
36
+
37
+ # Get a specific case
38
+ @assistly.case(12345)
39
+
40
+ # Update a specific case
41
+ @assistly.update_case(12345, :subject => "Something Else")
42
+
43
+ # List customers
44
+ @assistly.customers
45
+ @assistly.customers(:since_id => 12345, :count => 5)
46
+
47
+ # Get a specific customer
48
+ @assistly.customer(12345)
49
+
50
+ # Create a customer
51
+ @assistly.create_customer(:name => "Chris Warren", :twitter => "cdwarren")
52
+
53
+ # Update a customer
54
+ @assistly.update_customer(12345, :name => "Christopher Warren")
55
+
56
+ # Add a customer email
57
+ @assistly.create_customer_email(12345, "foo@example.com")
58
+ @assistly.create_customer_email(12345, "foo@example.com", :customer_contact_type => "work")
59
+
60
+ # Update a customer email
61
+ @assistly.update_customer_email(12345, 54321, :email => "foo@example.com")
62
+ @assistly.update_customer_email(12345, 54321, :customer_contact_type => "work")
63
+
64
+ # List interactions
65
+ @assistly.interactions
66
+ @assistly.interactions(:since_id => 12345)
67
+ @assistly.interactions(:since_id => 12345, :count => 5)
68
+
69
+ # Create an interaction
70
+ @assistly.create_interaction(:interaction_subject => "this is a test", :customer_email => "foo@example.com")
71
+
72
+ # List users
73
+ @assistly.users
74
+
75
+ # Get a specific user
76
+ @assistly.user(12345)
77
+
78
+ Contributing
79
+ ------------
80
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
81
+
82
+ Here are some ways *you* can contribute:
83
+
84
+ * by using alpha, beta, and prerelease versions
85
+ * by reporting bugs
86
+ * by suggesting new features
87
+ * by writing or editing documentation
88
+ * by writing specifications
89
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
90
+ * by refactoring code
91
+ * by closing [issues](http://github.com/chriswarren/assistly/issues)
92
+ * by reviewing patches
93
+
94
+ All contributors will be added to the [HISTORY](https://github.com/chriswarren/twitter/blob/master/HISTORY.mkd)
95
+ file and will receive the respect and gratitude of the community.
96
+
97
+ Submitting an Issue
98
+ -------------------
99
+ We use the [GitHub issue tracker](http://github.com/chriswarren/assistly/issues) to track bugs and
100
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
101
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
102
+ bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
103
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
104
+ operating system. Ideally, a bug report should include a pull request with failing specs.
105
+
106
+ Submitting a Pull Request
107
+ -------------------------
108
+ 1. Fork the project.
109
+ 2. Create a topic branch.
110
+ 3. Implement your feature or bug fix.
111
+ 4. Add documentation for your feature or bug fix.
112
+ 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
113
+ 6. Add specs for your feature or bug fix.
114
+ 7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
115
+ 8. Commit and push your changes.
116
+ 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
117
+
118
+ Copyright
119
+ ---------
120
+ Copyright (c) 2011 Chris Warren
121
+ See [LICENSE](https://github.com/chriswarren/assistly/blob/master/LICENSE.mkd) for details.
@@ -0,0 +1,23 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ namespace :doc do
11
+ require 'yard'
12
+ YARD::Rake::YardocTask.new do |task|
13
+ task.files = ['HISTORY.mkd', 'LICENSE.mkd', 'lib/**/*.rb']
14
+ task.options = [
15
+ '--protected',
16
+ '--output-dir', 'doc/yard',
17
+ '--tag', 'format:Supported formats',
18
+ '--tag', 'authenticated:Requires Authentication',
19
+ '--tag', 'rate_limited:Rate Limited',
20
+ '--markup', 'markdown',
21
+ ]
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/assistly/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.add_development_dependency('json', '~> 1.5')
6
+ s.add_development_dependency('nokogiri', '~> 1.4')
7
+ s.add_development_dependency('maruku', '~> 0.6')
8
+ s.add_development_dependency('rake', '~> 0.8')
9
+ s.add_development_dependency('rspec', '~> 2.5')
10
+ s.add_development_dependency('simplecov', '~> 0.4')
11
+ s.add_development_dependency('webmock', '~> 1.6')
12
+ s.add_development_dependency('yard', '~> 0.6')
13
+ s.add_development_dependency('ZenTest', '~> 4.5')
14
+ s.add_runtime_dependency('hashie', '~> 1.0.0')
15
+ s.add_runtime_dependency('faraday', '~> 0.6.0')
16
+ s.add_runtime_dependency('faraday_middleware', '~> 0.6.3')
17
+ s.add_runtime_dependency('jruby-openssl', '~> 0.7.2') if RUBY_PLATFORM == 'java'
18
+ s.add_runtime_dependency('multi_json', '~> 0.0.5')
19
+ s.add_runtime_dependency('multi_xml', '~> 0.2.0')
20
+ s.add_runtime_dependency('rash', '~> 0.3.0')
21
+ s.add_runtime_dependency('simple_oauth', '~> 0.1.4')
22
+ s.authors = ["Chris Warren"]
23
+ s.description = %q{A Ruby wrapper for the Assistly REST API, based on the Twitter gem}
24
+ s.post_install_message =<<eos
25
+ ********************************************************************************
26
+
27
+ Ruby wrapper for the Assistly API, based on https://github.com/jnunemaker/twitter/.
28
+
29
+ ********************************************************************************
30
+ eos
31
+ s.email = ['chris@zencoder.com']
32
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
33
+ s.files = `git ls-files`.split("\n")
34
+ s.homepage = 'https://github.com/chriswarren/assistly'
35
+ s.name = 'assistly'
36
+ s.platform = Gem::Platform::RUBY
37
+ s.require_paths = ['lib']
38
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
39
+ s.rubyforge_project = s.name
40
+ s.summary = %q{Ruby wrapper for the Assistly API, based on the Twitter gem}
41
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
42
+ s.version = Assistly::VERSION.dup
43
+ end
@@ -0,0 +1,26 @@
1
+ require 'assistly/error'
2
+ require 'assistly/configuration'
3
+ require 'assistly/api'
4
+ require 'assistly/client'
5
+ # require 'assistly/search'
6
+
7
+ module Assistly
8
+ extend Configuration
9
+
10
+ # Alias for Assistly::Client.new
11
+ #
12
+ # @return [Assistly::Client]
13
+ def self.client(options={})
14
+ Assistly::Client.new(options)
15
+ end
16
+
17
+ # Delegate to Assistly::Client
18
+ def self.method_missing(method, *args, &block)
19
+ return super unless client.respond_to?(method)
20
+ client.send(method, *args, &block)
21
+ end
22
+
23
+ def self.respond_to?(method)
24
+ client.respond_to?(method) || super
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ require 'assistly/connection'
2
+ require 'assistly/request'
3
+ require 'assistly/authentication'
4
+
5
+ module Assistly
6
+ # @private
7
+ class API
8
+ # @private
9
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
10
+
11
+ # Creates a new API
12
+ def initialize(options={})
13
+ options = Assistly.options.merge(options)
14
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include Connection
20
+ include Request
21
+ include Authentication
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module Assistly
2
+ # @private
3
+ module Authentication
4
+ private
5
+
6
+ # Authentication hash
7
+ #
8
+ # @return [Hash]
9
+ def authentication
10
+ {
11
+ :consumer_key => consumer_key,
12
+ :consumer_secret => consumer_secret,
13
+ :token => oauth_token,
14
+ :token_secret => oauth_token_secret
15
+ }
16
+ end
17
+
18
+ # Check whether user is authenticated
19
+ #
20
+ # @return [Boolean]
21
+ def authenticated?
22
+ authentication.values.all?
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Assistly
2
+ # Wrapper for the Assistly REST API
3
+ #
4
+ # @note All methods have been separated into modules and follow the same grouping used in {http://dev.assistly.com/doc the Assistly API Documentation}.
5
+ # @see http://dev.assistly.com/pages/every_developer
6
+ class Client < API
7
+ # Require client method modules after initializing the Client class in
8
+ # order to avoid a superclass mismatch error, allowing those modules to be
9
+ # Client-namespaced.
10
+ require 'assistly/client/utils'
11
+ require 'assistly/client/user'
12
+ require 'assistly/client/interaction'
13
+ require 'assistly/client/case'
14
+ require 'assistly/client/customer'
15
+
16
+ alias :api_endpoint :endpoint
17
+
18
+ include Assistly::Client::Utils
19
+
20
+ include Assistly::Client::User
21
+ include Assistly::Client::Interaction
22
+ include Assistly::Client::Case
23
+ include Assistly::Client::Customer
24
+ end
25
+ end
@@ -0,0 +1,51 @@
1
+ module Assistly
2
+ class Client
3
+ # Defines methods related to cases
4
+ module Case
5
+ # Returns extended information of cases
6
+ #
7
+ # @option options [Boolean, String, Integer]
8
+ # @example Return extended information for 12345
9
+ # Assistly.cases(:case_id => 12345)
10
+ # Assistly.cases(:email => "customer@example.com", :count => 5)
11
+ # Assistly.cases(:since_id => 12345)
12
+ # @format :json
13
+ # @authenticated true
14
+ # @see http://dev.assistly.com/docs/api/cases/show
15
+ def cases(*args)
16
+ options = args.last.is_a?(Hash) ? args.pop : {}
17
+ response = get("cases",options)
18
+ response['results']
19
+ end
20
+
21
+ # Returns extended information on a single case
22
+ #
23
+ # @option options [String]
24
+ # @example Return extended information for 12345
25
+ # Assistly.case(12345)
26
+ # Assistly.case(12345, :by => "external_id")
27
+ # @format :json
28
+ # @authenticated true
29
+ # @see http://dev.assistly.com/docs/api/cases/show
30
+ def case(id, *args)
31
+ options = args.last.is_a?(Hash) ? args.pop : {}
32
+ response = get("cases/#{id}",options)
33
+ response.case
34
+ end
35
+
36
+ # Updates a single case
37
+ #
38
+ # @option options [String]
39
+ # @example Return extended information for 12345
40
+ # Assistly.update_case(12345, :subject => "New Subject")
41
+ # @format :json
42
+ # @authenticated true
43
+ # @see http://dev.assistly.com/docs/api/cases/update
44
+ def update_case(id, *args)
45
+ options = args.last.is_a?(Hash) ? args.pop : {}
46
+ response = put("cases/#{id}",options)
47
+ response.case
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,108 @@
1
+ module Assistly
2
+ class Client
3
+ # Defines methods related to customers
4
+ module Customer
5
+ # Returns extended information of customers
6
+ #
7
+ # @option options [Boolean, String, Integer]
8
+ # @example Return extended information for customers
9
+ # Assistly.customers
10
+ # Assistly.customers(:since_id => 12345, :count => 5)
11
+ # @format :json
12
+ # @authenticated true
13
+ # @see http://dev.assistly.com/docs/api/customers
14
+ def customers(*args)
15
+ options = args.last.is_a?(Hash) ? args.pop : {}
16
+ response = get("customers",options)
17
+ response['results']
18
+ end
19
+
20
+ # Returns extended information on a single customer
21
+ #
22
+ # @option options [String]
23
+ # @example Return extended information for customer 12345
24
+ # Assistly.customer(12345)
25
+ # @format :json
26
+ # @authenticated true
27
+ # @see http://dev.assistly.com/docs/api/customers/show
28
+ def customer(id)
29
+ response = get("customers/#{id}")
30
+ response.customer
31
+ end
32
+
33
+ # Create a new customer
34
+ #
35
+ # @option options [String]
36
+ # @example Return extended information for 12345
37
+ # Assistly.create_customer(:name => "Chris Warren", :twitter => "cdwarren")
38
+ # @format :json
39
+ # @authenticated true
40
+ # @see http://dev.assistly.com/docs/api/customers/create
41
+ def create_customer(*args)
42
+ options = args.last.is_a?(Hash) ? args.pop : {}
43
+ response = post("customers",options)
44
+ if response['success']
45
+ return response['results']['customer']
46
+ else
47
+ return response['errors']
48
+ end
49
+ end
50
+
51
+ # Update a customer
52
+ #
53
+ # @option options [String]
54
+ # @example Return extended information for 12345
55
+ # Assistly.update_customer(12345, :name => "Christopher Warren")
56
+ # @format :json
57
+ # @authenticated true
58
+ # @see http://dev.assistly.com/docs/api/customers/update
59
+ def update_customer(id, *args)
60
+ options = args.last.is_a?(Hash) ? args.pop : {}
61
+ response = put("customers/#{id}",options)
62
+ if response['success']
63
+ return response['results']['customer']
64
+ else
65
+ return response['errors']
66
+ end
67
+ end
68
+
69
+ # Create a new customer email
70
+ #
71
+ # @option options [String]
72
+ # @example Return extended information for 12345
73
+ # Assistly.create_customer_email(12345, "foo@example.com")
74
+ # @format :json
75
+ # @authenticated true
76
+ # @see http://dev.assistly.com/docs/api/customers/emails/create
77
+ def create_customer_email(id, email, *args)
78
+ options = args.last.is_a?(Hash) ? args.pop : {}
79
+ options.merge!({:email => email})
80
+ response = post("customers/#{id}/emails",options)
81
+ if response['success']
82
+ return response['results']['email']
83
+ else
84
+ return response['errors']
85
+ end
86
+ end
87
+
88
+ # Update a customer's email
89
+ #
90
+ # @option options [String]
91
+ # @example Return extended information for 12345
92
+ # Assistly.update_customer_email(12345, 12345, :email => "foo@example.com")
93
+ # Assistly.update_customer_email(12345, 12345, :customer_contact_type => "work")
94
+ # @format :json
95
+ # @authenticated true
96
+ # @see http://dev.assistly.com/docs/api/customers/emails/update
97
+ def update_customer_email(id, email_id, *args)
98
+ options = args.last.is_a?(Hash) ? args.pop : {}
99
+ response = put("customers/#{id}/emails/#{email_id}",options)
100
+ if response['success']
101
+ return response['results']['email']
102
+ else
103
+ return response['errors']
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end