sambatech 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +4 -0
- data/README.md +47 -0
- data/Rakefile +3 -0
- data/lib/faraday/raise_http_exception.rb +52 -0
- data/lib/sambatech.rb +26 -0
- data/lib/sambatech/api.rb +22 -0
- data/lib/sambatech/client.rb +12 -0
- data/lib/sambatech/client/channels.rb +31 -0
- data/lib/sambatech/client/media.rb +41 -0
- data/lib/sambatech/configuration.rb +75 -0
- data/lib/sambatech/connection.rb +30 -0
- data/lib/sambatech/error.rb +20 -0
- data/lib/sambatech/request.rb +46 -0
- data/lib/sambatech/version.rb +3 -0
- data/sambatech.gemspec +23 -0
- data/spec/sambatech/api_spec.rb +65 -0
- data/spec/sambatech/client_spec.rb +10 -0
- data/spec/sambatech_spec.rb +74 -0
- data/spec/spec_helper.rb +58 -0
- metadata +205 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
sambatech
|
2
|
+
=========
|
3
|
+
|
4
|
+
A Ruby wrapper for the Sambatech REST and Search APIs
|
5
|
+
|
6
|
+
## History ##
|
7
|
+
|
8
|
+
I've made this Gem, because i need to migrate from Sambatech to an internal video plataform.
|
9
|
+
This Gem don't support *all* Sambatech API methods only the methods that I need for the migration.
|
10
|
+
All patchs/pull-requests are welcome :)
|
11
|
+
|
12
|
+
## Example of use:
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "sambatech"
|
16
|
+
|
17
|
+
Sambatech.configure do |config|
|
18
|
+
config.key = 'config_key'
|
19
|
+
config.endpoint = "http://sambatech_api/2.0/"
|
20
|
+
end
|
21
|
+
|
22
|
+
client = Sambatech.client()
|
23
|
+
|
24
|
+
### Get all medias that belongs to the categorie 42, and the media status is active
|
25
|
+
|
26
|
+
medias = client.all_medias({
|
27
|
+
:filter => 'id;title',
|
28
|
+
:search => "channelId:42;status:active",
|
29
|
+
:recursiveChannel => 'true',
|
30
|
+
:first => 0,
|
31
|
+
:limit => 2
|
32
|
+
})
|
33
|
+
|
34
|
+
### Get a specific media info by id ###
|
35
|
+
|
36
|
+
media = client.media('8a4980263260ee801423cad08f11bcd',{})
|
37
|
+
|
38
|
+
### Get Media file url
|
39
|
+
|
40
|
+
media_file = client.media_file_url(media.files.file.id,{})
|
41
|
+
|
42
|
+
### Get channel info, parent ###
|
43
|
+
|
44
|
+
channel = client.channel(channel_id,{})
|
45
|
+
|
46
|
+
|
47
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class RaiseHttpException < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
case response[:status].to_i
|
10
|
+
when 400
|
11
|
+
raise Sambatech::BadRequest, error_message_400(response)
|
12
|
+
when 404
|
13
|
+
raise Sambatech::NotFound, error_message_400(response)
|
14
|
+
when 500
|
15
|
+
raise Sambatech::InternalServerError, error_message_500(response, "Something is technically wrong.")
|
16
|
+
when 503
|
17
|
+
raise Sambatech::ServiceUnavailable, error_message_500(response, "Sambatech is rate limiting your requests.")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(app)
|
23
|
+
super app
|
24
|
+
@parser = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def error_message_400(response)
|
30
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def error_body(body)
|
34
|
+
# body gets passed as a string, not sure if it is passed as something else from other spots?
|
35
|
+
if not body.nil? and not body.empty? and body.kind_of?(String)
|
36
|
+
puts "Body: #{body}"
|
37
|
+
# removed multi_json thanks to wesnolte's commit
|
38
|
+
body = ::XML.parse(body)
|
39
|
+
end
|
40
|
+
|
41
|
+
if body.nil?
|
42
|
+
nil
|
43
|
+
elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
|
44
|
+
": #{body['meta']['error_message']}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def error_message_500(response, body=nil)
|
49
|
+
"#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/sambatech.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../sambatech/error', __FILE__)
|
2
|
+
require File.expand_path('../sambatech/configuration', __FILE__)
|
3
|
+
require File.expand_path('../sambatech/api', __FILE__)
|
4
|
+
require File.expand_path('../sambatech/client', __FILE__)
|
5
|
+
|
6
|
+
module Sambatech
|
7
|
+
extend Configuration
|
8
|
+
|
9
|
+
# Alias for Sambatech::Client.new
|
10
|
+
#
|
11
|
+
# @return [Sambatech::Client]
|
12
|
+
def self.client(options={})
|
13
|
+
Sambatech::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to Sambatech::Client
|
17
|
+
def self.method_missing(method, *args, &block)
|
18
|
+
return super unless client.respond_to?(method)
|
19
|
+
client.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delegate to Sambatech::Client
|
23
|
+
def self.respond_to?(method)
|
24
|
+
return client.respond_to?(method) || super
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
|
4
|
+
module Sambatech
|
5
|
+
# @private
|
6
|
+
class API
|
7
|
+
# @private
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
# Creates a new API
|
11
|
+
def initialize(options={})
|
12
|
+
options = Sambatech.options.merge(options)
|
13
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
include Connection
|
19
|
+
include Request
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Sambatech
|
2
|
+
# Wrapper for the Sambatech REST API
|
3
|
+
#
|
4
|
+
# @note All methods have been separated into modules and follow the same grouping used in {TODO:doc_URL the Sambatech API Documentation}.
|
5
|
+
# @see TODO:doc_url
|
6
|
+
class Client < API
|
7
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
|
8
|
+
include Sambatech::Client::Media
|
9
|
+
include Sambatech::Client::Channels
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "pp"
|
2
|
+
module Sambatech
|
3
|
+
class Client
|
4
|
+
# Defines methods related to media items
|
5
|
+
module Channels
|
6
|
+
# Returns extended information of a given media item
|
7
|
+
#
|
8
|
+
# @overload media_item(id)
|
9
|
+
# @param media-id [Hash] An Sambatech media item ID
|
10
|
+
# @return [Hashie::Mash] The requested media item.
|
11
|
+
# @example Return extended information for media item 1234
|
12
|
+
# Instagram.media_item(1324)
|
13
|
+
# @format :xml
|
14
|
+
#
|
15
|
+
# If getting this data of a protected user, you must authenticate (and be allowed to see that user).
|
16
|
+
# @rate_limited true
|
17
|
+
# @see TODO:docs url
|
18
|
+
# first [Número] (opcional) Posição inicial da lista. (valor padrão:0) query
|
19
|
+
# limit [Número] (opcional) Número de elementos na lista, limitado a 50. (valor padrão:50) query
|
20
|
+
# search [String] (opcional) O parâmetro search deve ser usado para definir critérios para a busca. Entre parênteses estão os operadores usados durante a busca (implícitos). Os únicos operadores que devem ser explicitados são: (>, <, >=, <=). O operador (==) deve ser usado como no exemplo anterior. Os campos do objeto Media que podem ser usados são:
|
21
|
+
def channel(*args,options)
|
22
|
+
id = args.first || 'self'
|
23
|
+
response = get("channels/#{id}", options)
|
24
|
+
response["Channel"]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Sambatech
|
2
|
+
class Client
|
3
|
+
# Defines methods related to media items
|
4
|
+
module Media
|
5
|
+
# Returns extended information of a given media item
|
6
|
+
#
|
7
|
+
# @overload media_item(id)
|
8
|
+
# @param media-id [Hash] An Sambatech media item ID
|
9
|
+
# @return [Hashie::Mash] The requested media item.
|
10
|
+
# @example Return extended information for media item 1234
|
11
|
+
# Instagram.media_item(1324)
|
12
|
+
# @format :xml
|
13
|
+
#
|
14
|
+
# If getting this data of a protected user, you must authenticate (and be allowed to see that user).
|
15
|
+
# @rate_limited true
|
16
|
+
# @see TODO:docs url
|
17
|
+
# first [Número] (opcional) Posição inicial da lista. (valor padrão:0) query
|
18
|
+
# limit [Número] (opcional) Número de elementos na lista, limitado a 50. (valor padrão:50) query
|
19
|
+
# search [String] (opcional) O parâmetro search deve ser usado para definir critérios para a busca. Entre parênteses estão os operadores usados durante a busca (implícitos). Os únicos operadores que devem ser explicitados são: (>, <, >=, <=). O operador (==) deve ser usado como no exemplo anterior. Os campos do objeto Media que podem ser usados são:
|
20
|
+
def media(*args,options)
|
21
|
+
id = args.first || 'self'
|
22
|
+
response = get("medias/#{id}", options)
|
23
|
+
response["Media"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def media_file_url(*args,options)
|
27
|
+
id = args.first || 'self'
|
28
|
+
response = get("medias/urls/#{id}", options)
|
29
|
+
response["URLs"]["URL"]["uri"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def all_medias(*args,options)
|
33
|
+
id = args.first || 'self'
|
34
|
+
response = get("medias", options)
|
35
|
+
response
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
module Sambatech
|
5
|
+
# Defines constants and methods related to configuration
|
6
|
+
module Configuration
|
7
|
+
# An array of valid keys in the options hash when configuring a {Sambatech::API}
|
8
|
+
VALID_OPTIONS_KEYS = [
|
9
|
+
:adapter,
|
10
|
+
:key,
|
11
|
+
:endpoint,
|
12
|
+
:user_agent,
|
13
|
+
:proxy
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
# An array of valid request/response formats
|
17
|
+
#
|
18
|
+
# @note Not all methods support the XML format.
|
19
|
+
VALID_FORMATS = [
|
20
|
+
:xml].freeze
|
21
|
+
|
22
|
+
# The adapter that will be used to connect if none is set
|
23
|
+
#
|
24
|
+
# @note The default faraday adapter is Net::HTTP.
|
25
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
26
|
+
|
27
|
+
# By default, don't set a user key
|
28
|
+
DEFAULT_KEY = 'you need to set a key'
|
29
|
+
|
30
|
+
# The endpoint that will be used to connect if none is set
|
31
|
+
#
|
32
|
+
# @note There is no reason to use any other endpoint at this time
|
33
|
+
DEFAULT_ENDPOINT = 'http://fast.api.liquidplatform.com/2.0'.freeze
|
34
|
+
|
35
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
36
|
+
#
|
37
|
+
# @note XML is the only available format at this time
|
38
|
+
DEFAULT_FORMAT = :xml
|
39
|
+
|
40
|
+
# By default, don't use a proxy server
|
41
|
+
DEFAULT_PROXY = nil
|
42
|
+
|
43
|
+
# The user agent that will be sent to the API endpoint if none is set
|
44
|
+
DEFAULT_USER_AGENT = "Sambatech Ruby Gem #{Sambatech::VERSION}".freeze
|
45
|
+
|
46
|
+
# @private
|
47
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
48
|
+
|
49
|
+
# When this module is extended, set all configuration options to their default values
|
50
|
+
def self.extended(base)
|
51
|
+
base.reset
|
52
|
+
end
|
53
|
+
|
54
|
+
# Convenience method to allow configuration options to be set in a block
|
55
|
+
def configure
|
56
|
+
yield self
|
57
|
+
end
|
58
|
+
|
59
|
+
# Create a hash of options and their values
|
60
|
+
def options
|
61
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
62
|
+
option.merge!(key => send(key))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Reset all configuration options to defaults
|
67
|
+
def reset
|
68
|
+
self.adapter = DEFAULT_ADAPTER
|
69
|
+
self.key = DEFAULT_KEY
|
70
|
+
self.endpoint = DEFAULT_ENDPOINT
|
71
|
+
self.user_agent = DEFAULT_USER_AGENT
|
72
|
+
self.proxy = DEFAULT_PROXY
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
3
|
+
|
4
|
+
module Sambatech
|
5
|
+
# @private
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection(raw=false)
|
10
|
+
options = {
|
11
|
+
:headers => {'Accept' => "application/xml; charset=utf-8", 'User-Agent' => user_agent},
|
12
|
+
:proxy => proxy,
|
13
|
+
:ssl => {:verify => false},
|
14
|
+
:url => endpoint,
|
15
|
+
:params => {:key => key},
|
16
|
+
}
|
17
|
+
|
18
|
+
Faraday::Connection.new(options) do |connection|
|
19
|
+
connection.use Faraday::Request::UrlEncoded
|
20
|
+
connection.use FaradayMiddleware::Mashify unless raw
|
21
|
+
unless raw
|
22
|
+
connection.use Faraday::Response::ParseXml
|
23
|
+
end
|
24
|
+
connection.use FaradayMiddleware::RaiseHttpException
|
25
|
+
connection.adapter(adapter)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sambatech
|
2
|
+
# Custom error class for rescuing from all Sambatech errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Sambatech returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Sambatech returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when Sambatech returns the HTTP status code 500
|
12
|
+
class InternalServerError < Error; end
|
13
|
+
|
14
|
+
# Raised when Sambatech returns the HTTP status code 503
|
15
|
+
class ServiceUnavailable < Error; end
|
16
|
+
|
17
|
+
# Raised when a subscription payload hash is invalid
|
18
|
+
class InvalidSignature < Error; end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Sambatech
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, options={}, raw=false, unformatted=false)
|
6
|
+
request(:get, path, options, raw, unformatted)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP POST request
|
10
|
+
def post(path, options={}, raw=false, unformatted=false)
|
11
|
+
request(:post, path, options, raw, unformatted)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP PUT request
|
15
|
+
def put(path, options={}, raw=false, unformatted=false)
|
16
|
+
request(:put, path, options, raw, unformatted)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Perform an HTTP DELETE request
|
20
|
+
def delete(path, options={}, raw=false, unformatted=false)
|
21
|
+
request(:delete, path, options, raw, unformatted)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Perform an HTTP request
|
27
|
+
def request(method, path, options, raw=false, unformatted=false)
|
28
|
+
response = connection(raw).send(method) do |request|
|
29
|
+
path = formatted_path(path) unless unformatted
|
30
|
+
case method
|
31
|
+
when :get, :delete
|
32
|
+
request.url(path, options)
|
33
|
+
when :post, :put
|
34
|
+
request.path = path
|
35
|
+
request.body = options unless options.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
raw ? response : response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
def formatted_path(path)
|
42
|
+
[path].compact.join('.')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/sambatech.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "sambatech/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.add_development_dependency('rspec', '~> 2.11.0')
|
7
|
+
s.add_development_dependency('webmock', '~> 1.6')
|
8
|
+
s.add_development_dependency('bluecloth', '~> 2.0.11')
|
9
|
+
s.add_runtime_dependency('faraday', ['>= 0.8.4', '< 0.9'])
|
10
|
+
s.add_runtime_dependency('faraday_middleware', ['>= 0.9.0', '< 0.10'])
|
11
|
+
s.add_runtime_dependency('multi_xml', ['~> 0.5.1'])
|
12
|
+
s.add_runtime_dependency('hashie', ['~> 1.2.0'])
|
13
|
+
s.add_runtime_dependency('rash', ['~> 0.3.2'])
|
14
|
+
s.name = 'sambatech'
|
15
|
+
s.version = Sambatech::VERSION.dup
|
16
|
+
s.date = '2012-12-05'
|
17
|
+
s.summary = %q{Ruby wrapper for the Sambatech API}
|
18
|
+
s.description = "A simple hello world gem"
|
19
|
+
s.authors = ["Lindolfo 'Lorn' Rodrigues"]
|
20
|
+
s.email = 'lorn@lornlab.org'
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.homepage = 'http://rubygems.org/gems/sambatech'
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Sambatech::API do
|
4
|
+
before do
|
5
|
+
@keys = Sambatech::Configuration::VALID_OPTIONS_KEYS
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with module configuration" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
Sambatech.configure do |config|
|
12
|
+
@keys.each do |key|
|
13
|
+
config.send("#{key}=", key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Sambatech.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should inherit module configuration" do
|
23
|
+
api = Sambatech::API.new
|
24
|
+
@keys.each do |key|
|
25
|
+
api.send(key).should == key
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with class configuration" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@configuration = {
|
33
|
+
:key => 'AT',
|
34
|
+
:adapter => :typhoeus,
|
35
|
+
:endpoint => 'http://tumblr.com/',
|
36
|
+
:proxy => 'http://shayne:sekret@proxy.example.com:8080',
|
37
|
+
:user_agent => 'Custom User Agent',
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
context "during initialization"
|
42
|
+
|
43
|
+
it "should override module configuration" do
|
44
|
+
api = Sambatech::API.new(@configuration)
|
45
|
+
@keys.each do |key|
|
46
|
+
api.send(key).should == @configuration[key]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "after initilization" do
|
51
|
+
|
52
|
+
it "should override module configuration after initialization" do
|
53
|
+
api = Sambatech::API.new
|
54
|
+
@configuration.each do |key, value|
|
55
|
+
api.send("#{key}=", value)
|
56
|
+
end
|
57
|
+
@keys.each do |key|
|
58
|
+
api.send(key).should == @configuration[key]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Sambatech::Client do
|
4
|
+
it "should connect using the endpoint configuration" do
|
5
|
+
client = Sambatech::Client.new
|
6
|
+
endpoint = URI.parse(client.endpoint)
|
7
|
+
connection = client.send(:connection).build_url(nil).to_s
|
8
|
+
(connection).should == endpoint.to_s.concat("?key=you+need+to+set+a+key")
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Sambatech do
|
4
|
+
after do
|
5
|
+
Sambatech.reset
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when delegating to a client" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
stub_get("users/self/feed.json").
|
12
|
+
to_return(:body => fixture("user_media_feed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".client" do
|
18
|
+
it "should be a Sambatech::Client" do
|
19
|
+
Sambatech.client.should be_a Sambatech::Client
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".adapter" do
|
24
|
+
it "should return the default adapter" do
|
25
|
+
Sambatech.adapter.should == Sambatech::Configuration::DEFAULT_ADAPTER
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".adapter=" do
|
30
|
+
it "should set the adapter" do
|
31
|
+
Sambatech.adapter = :typhoeus
|
32
|
+
Sambatech.adapter.should == :typhoeus
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".endpoint" do
|
37
|
+
it "should return the default endpoint" do
|
38
|
+
Sambatech.endpoint.should == Sambatech::Configuration::DEFAULT_ENDPOINT
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".endpoint=" do
|
43
|
+
it "should set the endpoint" do
|
44
|
+
Sambatech.endpoint = 'http://tumblr.com'
|
45
|
+
Sambatech.endpoint.should == 'http://tumblr.com'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".user_agent" do
|
50
|
+
it "should return the default user agent" do
|
51
|
+
Sambatech.user_agent.should == Sambatech::Configuration::DEFAULT_USER_AGENT
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe ".user_agent=" do
|
56
|
+
it "should set the user_agent" do
|
57
|
+
Sambatech.user_agent = 'Custom User Agent'
|
58
|
+
Sambatech.user_agent.should == 'Custom User Agent'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe ".configure" do
|
63
|
+
|
64
|
+
Sambatech::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
65
|
+
|
66
|
+
it "should set the #{key}" do
|
67
|
+
Sambatech.configure do |config|
|
68
|
+
config.send("#{key}=", key)
|
69
|
+
Sambatech.send(key).should == key
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
begin
|
2
|
+
require 'simplecov'
|
3
|
+
rescue LoadError
|
4
|
+
# ignore
|
5
|
+
else
|
6
|
+
SimpleCov.start do
|
7
|
+
add_group 'Sambatech', 'lib/Sambatech'
|
8
|
+
add_group 'Specs', 'spec'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require File.expand_path('../../lib/Sambatech', __FILE__)
|
13
|
+
|
14
|
+
require 'rspec'
|
15
|
+
require 'webmock/rspec'
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.include WebMock::API
|
18
|
+
end
|
19
|
+
|
20
|
+
def a_delete(path)
|
21
|
+
a_request(:delete, Sambatech.endpoint + path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def a_get(path)
|
25
|
+
a_request(:get, Sambatech.endpoint + path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def a_post(path)
|
29
|
+
a_request(:post, Sambatech.endpoint + path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def a_put(path)
|
33
|
+
a_request(:put, Sambatech.endpoint + path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_delete(path)
|
37
|
+
stub_request(:delete, Sambatech.endpoint + path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_get(path)
|
41
|
+
stub_request(:get, Sambatech.endpoint + path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def stub_post(path)
|
45
|
+
stub_request(:post, Sambatech.endpoint + path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def stub_put(path)
|
49
|
+
stub_request(:put, Sambatech.endpoint + path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def fixture_path
|
53
|
+
File.expand_path("../fixtures", __FILE__)
|
54
|
+
end
|
55
|
+
|
56
|
+
def fixture(file)
|
57
|
+
File.new(fixture_path + '/' + file)
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sambatech
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lindolfo 'Lorn' Rodrigues
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.11.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.11.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: webmock
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.6'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.6'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bluecloth
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.11
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.11
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: faraday
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.8.4
|
70
|
+
- - <
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.9'
|
73
|
+
type: :runtime
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.8.4
|
81
|
+
- - <
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.9'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: faraday_middleware
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.9.0
|
92
|
+
- - <
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0.10'
|
95
|
+
type: :runtime
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.9.0
|
103
|
+
- - <
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0.10'
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: multi_xml
|
108
|
+
requirement: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ~>
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 0.5.1
|
114
|
+
type: :runtime
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 0.5.1
|
122
|
+
- !ruby/object:Gem::Dependency
|
123
|
+
name: hashie
|
124
|
+
requirement: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ~>
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 1.2.0
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ~>
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 1.2.0
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: rash
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.3.2
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ~>
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.3.2
|
154
|
+
description: A simple hello world gem
|
155
|
+
email: lorn@lornlab.org
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- .gitignore
|
161
|
+
- .rspec
|
162
|
+
- README.md
|
163
|
+
- Rakefile
|
164
|
+
- lib/faraday/raise_http_exception.rb
|
165
|
+
- lib/sambatech.rb
|
166
|
+
- lib/sambatech/api.rb
|
167
|
+
- lib/sambatech/client.rb
|
168
|
+
- lib/sambatech/client/channels.rb
|
169
|
+
- lib/sambatech/client/media.rb
|
170
|
+
- lib/sambatech/configuration.rb
|
171
|
+
- lib/sambatech/connection.rb
|
172
|
+
- lib/sambatech/error.rb
|
173
|
+
- lib/sambatech/request.rb
|
174
|
+
- lib/sambatech/version.rb
|
175
|
+
- sambatech.gemspec
|
176
|
+
- spec/sambatech/api_spec.rb
|
177
|
+
- spec/sambatech/client_spec.rb
|
178
|
+
- spec/sambatech_spec.rb
|
179
|
+
- spec/spec_helper.rb
|
180
|
+
homepage: http://rubygems.org/gems/sambatech
|
181
|
+
licenses: []
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
none: false
|
188
|
+
requirements:
|
189
|
+
- - ! '>='
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
requirements: []
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 1.8.24
|
201
|
+
signing_key:
|
202
|
+
specification_version: 3
|
203
|
+
summary: Ruby wrapper for the Sambatech API
|
204
|
+
test_files: []
|
205
|
+
has_rdoc:
|