supportify_client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efaa4dbf90422f66f174e05665bddae16f84e315
4
+ data.tar.gz: cf4eb97233c0020c3d44c23e3e58045b6fc12f51
5
+ SHA512:
6
+ metadata.gz: fcd6a703366e417b15e2615d8899b711d3059fec2f4f9ae69ca6029aac5aa49d690734a5f94954b87c962ddc54a4e6095470b753a4b4f60a740c0b621c4c11eb
7
+ data.tar.gz: 35b04959f514c860a4265595e25ed39e2f363c02f98770ba5cbbb9566cf46c8edae8fda4b79d4c3c3ba3f279b0eff09da83e021215385be2df2e90b9e4a52c8c
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rest-client', '~> 1.7.1'
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.8.0"
7
+ gem "yard", "~> 0.7"
8
+ gem "rdoc", "~> 3.12"
9
+ gem "bundler", "~> 1.0"
10
+ gem "jeweler", "~> 2.0.1"
11
+ gem "simplecov", ">= 0"
12
+
13
+ gem "pry"
14
+ gem "pry-byebug"
15
+ end
16
+
17
+ group :test do
18
+ gem "webmock"
19
+ gem "factory_girl"
20
+ gem "faker"
21
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,121 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.5)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ byebug (2.7.0)
13
+ columnize (~> 0.3)
14
+ debugger-linecache (~> 1.2)
15
+ coderay (1.1.0)
16
+ columnize (0.8.9)
17
+ crack (0.4.2)
18
+ safe_yaml (~> 1.0.0)
19
+ debugger-linecache (1.2.0)
20
+ descendants_tracker (0.0.4)
21
+ thread_safe (~> 0.3, >= 0.3.1)
22
+ diff-lcs (1.1.3)
23
+ docile (1.1.5)
24
+ factory_girl (4.4.0)
25
+ activesupport (>= 3.0.0)
26
+ faker (1.4.3)
27
+ i18n (~> 0.5)
28
+ faraday (0.9.0)
29
+ multipart-post (>= 1.2, < 3)
30
+ git (1.2.8)
31
+ github_api (0.12.1)
32
+ addressable (~> 2.3)
33
+ descendants_tracker (~> 0.0.4)
34
+ faraday (~> 0.8, < 0.10)
35
+ hashie (>= 3.2)
36
+ multi_json (>= 1.7.5, < 2.0)
37
+ nokogiri (~> 1.6.3)
38
+ oauth2
39
+ hashie (3.3.0)
40
+ highline (1.6.21)
41
+ i18n (0.6.11)
42
+ jeweler (2.0.1)
43
+ builder
44
+ bundler (>= 1.0)
45
+ git (>= 1.2.5)
46
+ github_api
47
+ highline (>= 1.6.15)
48
+ nokogiri (>= 1.5.10)
49
+ rake
50
+ rdoc
51
+ json (1.8.1)
52
+ jwt (1.0.0)
53
+ method_source (0.8.2)
54
+ mime-types (2.3)
55
+ mini_portile (0.6.0)
56
+ minitest (5.4.0)
57
+ multi_json (1.10.1)
58
+ multi_xml (0.5.5)
59
+ multipart-post (2.0.0)
60
+ netrc (0.7.7)
61
+ nokogiri (1.6.3.1)
62
+ mini_portile (= 0.6.0)
63
+ oauth2 (1.0.0)
64
+ faraday (>= 0.8, < 0.10)
65
+ jwt (~> 1.0)
66
+ multi_json (~> 1.3)
67
+ multi_xml (~> 0.5)
68
+ rack (~> 1.2)
69
+ pry (0.10.1)
70
+ coderay (~> 1.1.0)
71
+ method_source (~> 0.8.1)
72
+ slop (~> 3.4)
73
+ pry-byebug (1.3.3)
74
+ byebug (~> 2.7)
75
+ pry (~> 0.10)
76
+ rack (1.5.2)
77
+ rake (10.3.2)
78
+ rdoc (3.12.2)
79
+ json (~> 1.4)
80
+ rest-client (1.7.2)
81
+ mime-types (>= 1.16, < 3.0)
82
+ netrc (~> 0.7)
83
+ rspec (2.8.0)
84
+ rspec-core (~> 2.8.0)
85
+ rspec-expectations (~> 2.8.0)
86
+ rspec-mocks (~> 2.8.0)
87
+ rspec-core (2.8.0)
88
+ rspec-expectations (2.8.0)
89
+ diff-lcs (~> 1.1.2)
90
+ rspec-mocks (2.8.0)
91
+ safe_yaml (1.0.3)
92
+ simplecov (0.9.0)
93
+ docile (~> 1.1.0)
94
+ multi_json
95
+ simplecov-html (~> 0.8.0)
96
+ simplecov-html (0.8.0)
97
+ slop (3.6.0)
98
+ thread_safe (0.3.4)
99
+ tzinfo (1.2.2)
100
+ thread_safe (~> 0.1)
101
+ webmock (1.18.0)
102
+ addressable (>= 2.3.6)
103
+ crack (>= 0.3.2)
104
+ yard (0.8.7.4)
105
+
106
+ PLATFORMS
107
+ ruby
108
+
109
+ DEPENDENCIES
110
+ bundler (~> 1.0)
111
+ factory_girl
112
+ faker
113
+ jeweler (~> 2.0.1)
114
+ pry
115
+ pry-byebug
116
+ rdoc (~> 3.12)
117
+ rest-client (~> 1.7.1)
118
+ rspec (~> 2.8.0)
119
+ simplecov
120
+ webmock
121
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jordan Yaker
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = supportify_ruby
2
+
3
+ Ruby library for Supportify.io.
4
+
5
+ == Contributing to supportify_ruby
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Supportify, Inc. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
18
+ gem.name = "supportify_client"
19
+ gem.homepage = "http://github.com/supportify/supportify_ruby"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Ruby client for the Supportify.io help and support API.}
22
+ gem.description = %Q{Ruby client for the Supportify.io help and support API.}
23
+ gem.email = "jordan.yaker@supportify.io"
24
+ gem.authors = ["Jordan Yaker", "Supportify, Inc."]
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ desc "Code coverage detail"
35
+ task :simplecov do
36
+ ENV['COVERAGE'] = "true"
37
+ Rake::Task['spec'].execute
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,17 @@
1
+ module Supportify
2
+ module Api
3
+ class Category
4
+ attr_accessor :id, :name, :description
5
+
6
+ def self.resource_name
7
+ 'categories'
8
+ end
9
+
10
+ def initialize(attributes = {})
11
+ self.id = attributes['id']
12
+ self.name = attributes['name']
13
+ self.description = attributes['description']
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module Supportify
2
+ module Api
3
+ class Error < ::RuntimeError
4
+ attr_accessor :code, :short_description, :long_description
5
+
6
+ def initialize(attributes = {})
7
+ self.code = attributes['code']
8
+ self.short_description = attributes['short_description']
9
+ self.long_description = attributes['long_description']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module Supportify
2
+ module Api
3
+ class Faq
4
+ attr_accessor :id, :question, :answer, :votes, :rating,
5
+ :categories, :tags
6
+
7
+ def self.resource_name
8
+ 'faqs'
9
+ end
10
+
11
+ def initialize(attributes = {})
12
+ self.id = attributes['id']
13
+ self.question = attributes['question']
14
+ self.answer = attributes['answer']
15
+ self.rating = attributes['rating']
16
+ self.votes = attributes['votes']
17
+
18
+ self.categories = (attributes['categories'] || []).map { |c| Category.new c }
19
+ self.tags = (attributes['tags'] || []).map { |t| Tag.new t }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module Supportify
2
+ module Api
3
+ class Tag
4
+ attr_accessor :id, :name, :description
5
+
6
+ def self.resource_name
7
+ 'tags'
8
+ end
9
+
10
+ def initialize(attributes = {})
11
+ self.id = attributes['id']
12
+ self.name = attributes['name']
13
+ self.description = attributes['description']
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ require 'supportify_client/api/category'
2
+ require 'supportify_client/api/error'
3
+ require 'supportify_client/api/faq'
4
+ require 'supportify_client/api/tag'
@@ -0,0 +1,49 @@
1
+ require 'supportify_client/api'
2
+ require 'supportify_client/factory'
3
+ require 'supportify_client/gateway'
4
+ require 'supportify_client/repository'
5
+
6
+ module Supportify
7
+ class Client
8
+ class << self
9
+ def base_url
10
+ "https://api.supportify.io"
11
+ end
12
+
13
+ def versions
14
+ %w{v1}
15
+ end
16
+
17
+ def headers
18
+ {
19
+ user_agent: "supportify-ruby-gem/#{Supportify::VERSION}",
20
+ content_type: :json,
21
+ accept: :json
22
+ }
23
+ end
24
+ end
25
+
26
+ include Gateway
27
+ include Repository
28
+ include Factory
29
+
30
+ def initialize(args = {})
31
+ @config = args
32
+
33
+ @config[:api_key] ||= ENV["SUPPORTIFY_API_KEY"]
34
+ @config[:app_key] ||= ENV["SUPPORTIFY_APP_KEY"]
35
+ @config[:version] ||= self.class.versions.last
36
+ end
37
+
38
+ protected
39
+
40
+ def headers
41
+ self.class.headers.merge 'X-Supportify-ApiKey' => @config[:api_key],
42
+ 'X-Supportify-AppKey' => @config[:app_key]
43
+ end
44
+
45
+ def base_url
46
+ "#{self.class.base_url}/#{@config[:version]}"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+
3
+ module Supportify
4
+ module Factory
5
+ def parse(body)
6
+ attributes = JSON.parse(body)
7
+ key = attributes.keys.first
8
+
9
+ klass = case key
10
+ when /^faq(s?)/i then Supportify::Api::Faq
11
+ when /^categor(ies|y)/i then Supportify::Api::Category
12
+ when /^tag(s?)/i then Supportify::Api::Tag
13
+ else Supportify::Api::Error
14
+ end
15
+
16
+ unless klass.nil?
17
+ if attributes[key].is_a? Array or attributes[key].is_a? Hash
18
+ attributes = attributes[key]
19
+ end
20
+
21
+ if attributes.is_a? Array
22
+ attributes.map { |a| klass.new a }
23
+ else
24
+ klass.new attributes
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'pry'
2
+ module Supportify
3
+ module Gateway
4
+ def get(klass, options)
5
+ request :get, klass, options
6
+ end
7
+
8
+ def post(klass, options)
9
+ request :post, klass, options
10
+ end
11
+
12
+ def request(method, klass, options)
13
+ params = options.extract_options!
14
+ id = options.pop if options.any?
15
+
16
+ url = "#{self.base_url}/#{klass.resource_name}"
17
+ url << "/#{id}" unless id.nil?
18
+
19
+ RestClient::Request.execute method: method, url: url, payload: params, headers: self.headers do |response, request, result|
20
+ case response.code
21
+ when 404
22
+ nil
23
+ when 200
24
+ parse response unless response.nil? or response =~ /\A[[:space:]]*\z/
25
+ when 400, 401, 404, 500
26
+ raise parse(response)
27
+ else
28
+ response.return!(request, result)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ module Supportify
2
+ module Repository
3
+ def categories(*args)
4
+ get Supportify::Api::Category, args
5
+ end
6
+
7
+ def faqs(*args)
8
+ get Supportify::Api::Faq, args
9
+ end
10
+
11
+ def tags(*args)
12
+ get Supportify::Api::Tag, args
13
+ end
14
+
15
+ def vote(*args)
16
+ post Supportify::Api::Faq, args
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Supportify
2
+ VERSION = File.read File.expand_path('../../../VERSION', __FILE__)
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'rest_client'
2
+
3
+ require 'supportify_client/client'
4
+ require 'supportify_client/version'
5
+
6
+ module RestClient::AbstractResponse
7
+ def success?
8
+ (200..207).include? code
9
+ end
10
+ end
11
+
12
+ if !defined?(ActiveSupport) or ActiveSupport::VERSION::MAJOR < 3
13
+ Array.class_eval do
14
+ def extract_options!
15
+ last.is_a?(::Hash) ? pop : {}
16
+ end
17
+ end
18
+ end
data/spec/factories.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'faker'
2
+
3
+ FactoryGirl.define do
4
+ factory :tag, class: Hash do
5
+ id { rand(100000) }
6
+ name { Faker::Lorem.word }
7
+ description { Faker::Lorem.paragraph }
8
+
9
+ initialize_with { attributes }
10
+ end
11
+
12
+ factory :category, class: Hash do
13
+ id { rand(100000) }
14
+ name { Faker::Lorem.word }
15
+ description { Faker::Lorem.paragraph }
16
+
17
+ initialize_with { attributes }
18
+ end
19
+
20
+ factory :faq, class: Hash do
21
+ id { rand(100000) }
22
+ question { Faker::Lorem.sentence }
23
+ answer { Faker::Lorem.paragraph }
24
+ votes { rand(100) }
25
+ rating { rand }
26
+
27
+ initialize_with { attributes }
28
+ end
29
+
30
+ factory :faq_with_categories_and_tags, parent: :faq do
31
+ tags { build_list :tag, rand(1..5) }
32
+ categories { build_list :category, rand(1..5) }
33
+ end
34
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Category Retrieval" do
4
+ let(:api_key) { 'api_key' }
5
+ let(:app_key) { 'app_key' }
6
+ let(:version) { 'v1' }
7
+
8
+ subject do
9
+ Supportify::Client.new api_key: api_key,
10
+ app_key: app_key,
11
+ version: version
12
+ end
13
+
14
+ describe "When retrieving multiple Categories" do
15
+ let(:categories) { build_list :category, rand(1..5) }
16
+ let(:response) { subject.categories }
17
+
18
+ before do
19
+ stub_request(:any, "https://api.supportify.io/v1/categories")
20
+ .to_return(status: 200, body: { 'categories' => categories }.to_json, headers: {})
21
+ end
22
+
23
+ it { response.should be_a Array }
24
+ it { response.each { |r| r.should be_a Supportify::Api::Category } }
25
+ end
26
+
27
+ describe "When retrieving a single Category" do
28
+ let(:category) { build :category }
29
+ let(:response) { subject.categories(1) }
30
+
31
+ before do
32
+ stub_request(:any, "https://api.supportify.io/v1/categories/1")
33
+ .to_return(status: 200, body: { 'category' => category }.to_json, headers: {})
34
+ end
35
+
36
+ it { response.should be_a(Supportify::Api::Category) }
37
+ end
38
+
39
+ describe "When passing in additional arguments" do
40
+ let(:fields) { 'id,name' }
41
+ let(:sort) { 'name-asc' }
42
+
43
+ before do
44
+ stub_request(:get, "https://api.supportify.io/v1/categories").
45
+ to_return(:status => 200, :body => "", :headers => {})
46
+
47
+ subject.categories fields: fields, sort: sort
48
+ end
49
+
50
+ it "should have passed along the arguments" do
51
+ WebMock.should have_requested(:get, "https://api.supportify.io/v1/categories")
52
+ .with(body: { fields: fields, sort: sort })
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Supportify::Client do
4
+ let(:api_key) { 'api_key' }
5
+ let(:app_key) { 'app_key' }
6
+ let(:version) { 'v1' }
7
+
8
+ subject do
9
+ Supportify::Client.new api_key: api_key,
10
+ app_key: app_key,
11
+ version: version
12
+ end
13
+
14
+ it { Supportify::Client.base_url.should == 'https://api.supportify.io' }
15
+ it { Supportify::Client.versions.should include('v1') }
16
+ it { Supportify::Client.headers[:user_agent].should == "supportify-ruby-gem/#{Supportify::VERSION}" }
17
+ it { Supportify::Client.headers[:content_type].should == :json }
18
+ it { Supportify::Client.headers[:accept].should == :json }
19
+
20
+ describe "when initializing without variables" do
21
+ let(:target) { Supportify::Client.new }
22
+ let(:config) { target.instance_variable_get(:@config) }
23
+
24
+ before do
25
+ ENV["SUPPORTIFY_API_KEY"] = api_key
26
+ ENV["SUPPORTIFY_APP_KEY"] = app_key
27
+ end
28
+
29
+ it { config[:api_key].should == api_key }
30
+ it { config[:app_key].should == app_key }
31
+ end
32
+
33
+ describe "when making a request" do
34
+ before do
35
+ stub_request(:any, "https://api.supportify.io/v1/faqs")
36
+ .to_return(:status => 200, :body => "", :headers => {})
37
+
38
+ subject.faqs
39
+ end
40
+
41
+ it "should have passed in the proper headers" do
42
+ WebMock.should have_requested(:get, "https://api.supportify.io/v1/faqs")
43
+ .with(headers: {
44
+ 'X-Supportify-ApiKey' => api_key,
45
+ 'X-Supportify-AppKey' => app_key,
46
+ 'User-Agent' => "supportify-ruby-gem/#{Supportify::VERSION}"
47
+ })
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Error Handling" do
4
+ let(:api_key) { 'api_key' }
5
+ let(:app_key) { 'app_key' }
6
+ let(:version) { 'v1' }
7
+
8
+ subject do
9
+ Supportify::Client.new api_key: api_key,
10
+ app_key: app_key,
11
+ version: version
12
+ end
13
+
14
+ describe "500" do
15
+ let(:code) { 500 }
16
+ let(:short_description) { 'UnexpectedError' }
17
+ let(:long_description) { "An unexpected error has occurred. Please try again. If the error continues to occur, please contact support." }
18
+ let(:error) do
19
+ { code: code, short_description: short_description, long_description: long_description }.to_json
20
+ end
21
+
22
+ before do
23
+ stub_request(:any, "https://api.supportify.io/v1/faqs")
24
+ .to_return(status: code, body: error, headers: {})
25
+ end
26
+
27
+ it "should return the correct error" do
28
+ expect { subject.faqs }.to raise_error do |error|
29
+ error.code.should == code
30
+ error.short_description.should == short_description
31
+ error.long_description.should == long_description
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "400" do
37
+ let(:code) { 400 }
38
+ let(:short_description) { 'BadRequest' }
39
+ let(:long_description) { "The system did not receive the necessary parameters to complete the request. Please check your request and try again." }
40
+ let(:error) do
41
+ { code: code, short_description: short_description, long_description: long_description }.to_json
42
+ end
43
+
44
+ before do
45
+ stub_request(:any, "https://api.supportify.io/v1/faqs")
46
+ .to_return(status: code, body: error, headers: {})
47
+ end
48
+
49
+ it "should return the correct error" do
50
+ expect { subject.faqs }.to raise_error do |error|
51
+ error.code.should == code
52
+ error.short_description.should == short_description
53
+ error.long_description.should == long_description
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "401" do
59
+ let(:code) { 401 }
60
+ let(:short_description) { 'Unauthorized' }
61
+ let(:long_description) { 'The system was unable to authenticate your request. Please check your credentials and try again.' }
62
+ let(:error) do
63
+ { code: code, short_description: short_description, long_description: long_description }.to_json
64
+ end
65
+
66
+ before do
67
+ stub_request(:any, "https://api.supportify.io/v1/faqs")
68
+ .to_return(status: code, body: error, headers: {})
69
+ end
70
+
71
+ it "should return the correct error" do
72
+ expect { subject.faqs }.to raise_error do |error|
73
+ error.code.should == code
74
+ error.short_description.should == short_description
75
+ error.long_description.should == long_description
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "404" do
81
+ let(:code) { 404 }
82
+ let(:short_description) { 'NotFound' }
83
+ let(:long_description) { 'The system was unable to locate the specified object. Please check your request and try again.'}
84
+ let(:error) do
85
+ { code: code, short_description: short_description, long_description: long_description }.to_json
86
+ end
87
+ let(:response) { subject.faqs }
88
+
89
+ before do
90
+ stub_request(:any, "https://api.supportify.io/v1/faqs")
91
+ .to_return(status: code, body: error, headers: {})
92
+ end
93
+
94
+ it { response.should == nil }
95
+ end
96
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Faq Retrieval" do
4
+ let(:api_key) { 'api_key' }
5
+ let(:app_key) { 'app_key' }
6
+ let(:version) { 'v1' }
7
+
8
+ subject do
9
+ Supportify::Client.new api_key: api_key,
10
+ app_key: app_key,
11
+ version: version
12
+ end
13
+
14
+ describe "When retrieving multiple Faqs" do
15
+ let(:faqs) { build_list :faq_with_categories_and_tags, rand(1..5) }
16
+ let(:response) { subject.faqs }
17
+
18
+ before do
19
+ stub_request(:any, "https://api.supportify.io/v1/faqs")
20
+ .to_return(status: 200, body: { 'faqs' => faqs }.to_json, headers: {})
21
+ end
22
+
23
+ it { response.should be_a Array }
24
+ it { response.each { |r| r.should be_a Supportify::Api::Faq } }
25
+ end
26
+
27
+ describe "When retrieving a single Faq" do
28
+ let(:faq) { build :faq_with_categories_and_tags }
29
+ let(:response) { subject.faqs(1) }
30
+
31
+ before do
32
+ stub_request(:any, "https://api.supportify.io/v1/faqs/1")
33
+ .to_return(status: 200, body: { 'faq' => faq }.to_json, headers: {})
34
+ end
35
+
36
+ it { response.should be_a(Supportify::Api::Faq) }
37
+ end
38
+
39
+ describe "When passing in additional arguments" do
40
+ let(:fields) { 'id,question,answer' }
41
+ let(:sort) { 'question-asc' }
42
+
43
+ before do
44
+ stub_request(:get, "https://api.supportify.io/v1/faqs").
45
+ to_return(:status => 200, :body => "", :headers => {})
46
+
47
+ subject.faqs fields: fields, sort: sort
48
+ end
49
+
50
+ it "should have passed along the arguments" do
51
+ WebMock.should have_requested(:get, "https://api.supportify.io/v1/faqs")
52
+ .with(body: { fields: fields, sort: sort })
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Tag Retrieval" do
4
+ let(:api_key) { 'api_key' }
5
+ let(:app_key) { 'app_key' }
6
+ let(:version) { 'v1' }
7
+
8
+ subject do
9
+ Supportify::Client.new api_key: api_key,
10
+ app_key: app_key,
11
+ version: version
12
+ end
13
+
14
+ describe "When retrieving multiple Tags" do
15
+ let(:tags) { build_list :tag, rand(1..5) }
16
+ let(:response) { subject.tags }
17
+
18
+ before do
19
+ stub_request(:any, "https://api.supportify.io/v1/tags")
20
+ .to_return(status: 200, body: { 'tags' => tags }.to_json, headers: {})
21
+ end
22
+
23
+ it { response.should be_a Array }
24
+ it { response.each { |r| r.should be_a Supportify::Api::Tag } }
25
+ end
26
+
27
+ describe "When retrieving a single Tag" do
28
+ let(:tag) { build :tag }
29
+ let(:response) { subject.tags(1) }
30
+
31
+ before do
32
+ stub_request(:any, "https://api.supportify.io/v1/tags/1")
33
+ .to_return(status: 200, body: { 'tag' => tag }.to_json, headers: {})
34
+ end
35
+
36
+ it { response.should be_a(Supportify::Api::Tag) }
37
+ end
38
+
39
+ describe "When passing in additional arguments" do
40
+ let(:fields) { 'id,name' }
41
+ let(:sort) { 'name-asc' }
42
+
43
+ before do
44
+ stub_request(:get, "https://api.supportify.io/v1/tags").
45
+ to_return(:status => 200, :body => "", :headers => {})
46
+
47
+ subject.tags fields: fields, sort: sort
48
+ end
49
+
50
+ it "should have passed along the arguments" do
51
+ WebMock.should have_requested(:get, "https://api.supportify.io/v1/tags")
52
+ .with(body: { fields: fields, sort: sort })
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'supportify_client'
3
+ require 'webmock/rspec'
4
+
5
+ # Requires supporting files with custom matchers and macros, etc,
6
+ # in ./support/ and its subdirectories.
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.order = 'random'
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.find_definitions
4
+
5
+ RSpec.configure do |config|
6
+ config.include FactoryGirl::Syntax::Methods
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -0,0 +1,16 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
@@ -0,0 +1,93 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "supportify_client"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jordan Yaker", "Supportify, Inc."]
12
+ s.date = "2014-08-27"
13
+ s.description = "Ruby client for the Supportify.io help and support API."
14
+ s.email = "jordan.yaker@supportify.io"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/supportify_client.rb",
29
+ "lib/supportify_client/api.rb",
30
+ "lib/supportify_client/api/category.rb",
31
+ "lib/supportify_client/api/error.rb",
32
+ "lib/supportify_client/api/faq.rb",
33
+ "lib/supportify_client/api/tag.rb",
34
+ "lib/supportify_client/client.rb",
35
+ "lib/supportify_client/factory.rb",
36
+ "lib/supportify_client/gateway.rb",
37
+ "lib/supportify_client/repository.rb",
38
+ "lib/supportify_client/version.rb",
39
+ "spec/factories.rb",
40
+ "spec/features/categories_spec.rb",
41
+ "spec/features/client_spec.rb",
42
+ "spec/features/errors_spec.rb",
43
+ "spec/features/faqs_spec.rb",
44
+ "spec/features/tags_spec.rb",
45
+ "spec/spec_helper.rb",
46
+ "spec/support/factory_girl.rb",
47
+ "spec/support/load_paths.rb",
48
+ "spec/support/simple_cov.rb",
49
+ "supportify_client.gemspec"
50
+ ]
51
+ s.homepage = "http://github.com/supportify/supportify_ruby"
52
+ s.licenses = ["MIT"]
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = "2.0.6"
55
+ s.summary = "Ruby client for the Supportify.io help and support API."
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 4
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_runtime_dependency(%q<rest-client>, ["~> 1.7.1"])
62
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
63
+ s.add_development_dependency(%q<yard>, ["~> 0.7"])
64
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
66
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
67
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
68
+ s.add_development_dependency(%q<pry>, [">= 0"])
69
+ s.add_development_dependency(%q<pry-byebug>, [">= 0"])
70
+ else
71
+ s.add_dependency(%q<rest-client>, ["~> 1.7.1"])
72
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
73
+ s.add_dependency(%q<yard>, ["~> 0.7"])
74
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
75
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
77
+ s.add_dependency(%q<simplecov>, [">= 0"])
78
+ s.add_dependency(%q<pry>, [">= 0"])
79
+ s.add_dependency(%q<pry-byebug>, [">= 0"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<rest-client>, ["~> 1.7.1"])
83
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
84
+ s.add_dependency(%q<yard>, ["~> 0.7"])
85
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
86
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
87
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
88
+ s.add_dependency(%q<simplecov>, [">= 0"])
89
+ s.add_dependency(%q<pry>, [">= 0"])
90
+ s.add_dependency(%q<pry-byebug>, [">= 0"])
91
+ end
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: supportify_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Yaker
8
+ - Supportify, Inc.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 1.7.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 1.7.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.8.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 2.8.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: yard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '0.7'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '0.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rdoc
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3.12'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '1.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: jeweler
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 2.0.1
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: 2.0.1
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: pry-byebug
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description: Ruby client for the Supportify.io help and support API.
141
+ email: jordan.yaker@supportify.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - LICENSE.txt
146
+ - README.rdoc
147
+ files:
148
+ - .document
149
+ - .rspec
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - LICENSE.txt
153
+ - README.rdoc
154
+ - Rakefile
155
+ - VERSION
156
+ - lib/supportify_client.rb
157
+ - lib/supportify_client/api.rb
158
+ - lib/supportify_client/api/category.rb
159
+ - lib/supportify_client/api/error.rb
160
+ - lib/supportify_client/api/faq.rb
161
+ - lib/supportify_client/api/tag.rb
162
+ - lib/supportify_client/client.rb
163
+ - lib/supportify_client/factory.rb
164
+ - lib/supportify_client/gateway.rb
165
+ - lib/supportify_client/repository.rb
166
+ - lib/supportify_client/version.rb
167
+ - spec/factories.rb
168
+ - spec/features/categories_spec.rb
169
+ - spec/features/client_spec.rb
170
+ - spec/features/errors_spec.rb
171
+ - spec/features/faqs_spec.rb
172
+ - spec/features/tags_spec.rb
173
+ - spec/spec_helper.rb
174
+ - spec/support/factory_girl.rb
175
+ - spec/support/load_paths.rb
176
+ - spec/support/simple_cov.rb
177
+ - supportify_client.gemspec
178
+ homepage: http://github.com/supportify/supportify_ruby
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.0.6
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Ruby client for the Supportify.io help and support API.
202
+ test_files: []