supportify_client 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -4
- data/Gemfile.lock +47 -39
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/lib/supportify_client/api/supportify_api.rb +560 -0
- data/lib/supportify_client/api_client.rb +271 -0
- data/lib/supportify_client/api_error.rb +24 -0
- data/lib/supportify_client/configuration.rb +187 -0
- data/lib/supportify_client/models/base_object.rb +87 -0
- data/lib/supportify_client/models/category.rb +53 -0
- data/lib/supportify_client/models/error.rb +53 -0
- data/lib/supportify_client/models/faq.rb +161 -0
- data/lib/supportify_client/models/info.rb +45 -0
- data/lib/supportify_client/models/tag.rb +53 -0
- data/lib/supportify_client/models/user.rb +45 -0
- data/lib/supportify_client.rb +30 -14
- data/spec/features/.gitkeep +0 -0
- data/supportify_client.gemspec +27 -27
- metadata +38 -26
- data/lib/supportify_client/api/category.rb +0 -17
- data/lib/supportify_client/api/error.rb +0 -13
- data/lib/supportify_client/api/faq.rb +0 -23
- data/lib/supportify_client/api/search.rb +0 -9
- data/lib/supportify_client/api/tag.rb +0 -17
- data/lib/supportify_client/api.rb +0 -5
- data/lib/supportify_client/client.rb +0 -49
- data/lib/supportify_client/factory.rb +0 -29
- data/lib/supportify_client/gateway.rb +0 -32
- data/lib/supportify_client/repository.rb +0 -23
- data/spec/features/categories_spec.rb +0 -55
- data/spec/features/client_spec.rb +0 -50
- data/spec/features/errors_spec.rb +0 -96
- data/spec/features/faqs_spec.rb +0 -55
- data/spec/features/search_spec.rb +0 -29
- data/spec/features/tags_spec.rb +0 -55
@@ -1,49 +0,0 @@
|
|
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
|
@@ -1,29 +0,0 @@
|
|
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
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Supportify
|
2
|
-
module Gateway
|
3
|
-
def get(klass, options)
|
4
|
-
request :get, klass, options
|
5
|
-
end
|
6
|
-
|
7
|
-
def post(klass, options)
|
8
|
-
request :post, klass, options
|
9
|
-
end
|
10
|
-
|
11
|
-
def request(method, klass, options)
|
12
|
-
params = options.extract_options!
|
13
|
-
id = options.pop if options.any?
|
14
|
-
|
15
|
-
url = "#{self.base_url}/#{klass.resource_name}"
|
16
|
-
url << "/#{id}" unless id.nil?
|
17
|
-
|
18
|
-
RestClient::Request.execute method: method, url: url, payload: params, headers: self.headers do |response, request, result|
|
19
|
-
case response.code
|
20
|
-
when 404
|
21
|
-
nil
|
22
|
-
when 200
|
23
|
-
parse response unless response.nil? or response =~ /\A[[:space:]]*\z/
|
24
|
-
when 400, 401, 404, 500
|
25
|
-
raise parse(response)
|
26
|
-
else
|
27
|
-
response.return!(request, result)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,23 +0,0 @@
|
|
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 search(*args)
|
16
|
-
get Supportify::Api::Search, args
|
17
|
-
end
|
18
|
-
|
19
|
-
def vote(*args)
|
20
|
-
post Supportify::Api::Faq, args
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,55 +0,0 @@
|
|
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
|
@@ -1,50 +0,0 @@
|
|
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
|
@@ -1,96 +0,0 @@
|
|
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
|
data/spec/features/faqs_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
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
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "Searching" 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 searching for content" do
|
15
|
-
let(:query) { 'testing' }
|
16
|
-
|
17
|
-
before do
|
18
|
-
stub_request(:get, "https://api.supportify.io/v1/search").
|
19
|
-
to_return(:status => 200, :body => "", :headers => {})
|
20
|
-
|
21
|
-
subject.search query: query
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should have passed along the arguments" do
|
25
|
-
WebMock.should have_requested(:get, "https://api.supportify.io/v1/search")
|
26
|
-
.with(body: { query: query })
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/features/tags_spec.rb
DELETED
@@ -1,55 +0,0 @@
|
|
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
|