echor 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of echor might be problematic. Click here for more details.
- data/.document +5 -0
- data/.rspec +3 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/echor.gemspec +80 -0
- data/lib/echor.rb +30 -0
- data/lib/echor/api.rb +14 -0
- data/lib/echor/backplane.rb +60 -0
- data/lib/echor/client.rb +24 -0
- data/lib/echor/configuration.rb +89 -0
- data/lib/echor/search.rb +28 -0
- data/lib/echor/user.rb +31 -0
- data/lib/echor/utils.rb +19 -0
- data/spec/echor_spec.rb +30 -0
- data/spec/search_spec.rb +46 -0
- data/spec/spec_helper.rb +12 -0
- metadata +204 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem "httparty"
|
3
|
+
gem "json"
|
4
|
+
gem "rash"
|
5
|
+
|
6
|
+
# Add dependencies required to use your gem here.
|
7
|
+
# Example:
|
8
|
+
# gem "activesupport", ">= 2.3.5"
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rspec", "~> 2.3.0"
|
14
|
+
gem "yard", "~> 0.6.0"
|
15
|
+
gem "bundler", "~> 1.0.0"
|
16
|
+
gem "jeweler", "~> 1.6.0"
|
17
|
+
gem "rcov", ">= 0"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
crack (0.1.8)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
hashie (1.0.0)
|
8
|
+
httparty (0.7.7)
|
9
|
+
crack (= 0.1.8)
|
10
|
+
jeweler (1.6.0)
|
11
|
+
bundler (~> 1.0.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
json (1.5.1)
|
15
|
+
rake (0.8.7)
|
16
|
+
rash (0.3.0)
|
17
|
+
hashie (~> 1.0.0)
|
18
|
+
rcov (0.9.9)
|
19
|
+
rspec (2.3.0)
|
20
|
+
rspec-core (~> 2.3.0)
|
21
|
+
rspec-expectations (~> 2.3.0)
|
22
|
+
rspec-mocks (~> 2.3.0)
|
23
|
+
rspec-core (2.3.1)
|
24
|
+
rspec-expectations (2.3.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.3.0)
|
27
|
+
yard (0.6.8)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
httparty
|
35
|
+
jeweler (~> 1.6.0)
|
36
|
+
json
|
37
|
+
rash
|
38
|
+
rcov
|
39
|
+
rspec (~> 2.3.0)
|
40
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Pedro
|
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
|
+
= echor
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to echor
|
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) 2011 Pedro. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "echor"
|
18
|
+
gem.homepage = "http://github.com/pedrodelgallego/echor"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A client for the Echo API}
|
21
|
+
gem.description = %Q{ Echo ruby wrappper }
|
22
|
+
gem.email = "pedro.delgallego@gmail.com"
|
23
|
+
gem.authors = ["Pedro Del Gallego"]
|
24
|
+
|
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
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
data/echor.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
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 = %q{echor}
|
8
|
+
s.version = "0.1.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Pedro Del Gallego}]
|
12
|
+
s.date = %q{2011-05-29}
|
13
|
+
s.description = %q{ Echo ruby wrappper }
|
14
|
+
s.email = %q{pedro.delgallego@gmail.com}
|
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
|
+
"echor.gemspec",
|
29
|
+
"lib/echor.rb",
|
30
|
+
"lib/echor/api.rb",
|
31
|
+
"lib/echor/backplane.rb",
|
32
|
+
"lib/echor/client.rb",
|
33
|
+
"lib/echor/configuration.rb",
|
34
|
+
"lib/echor/search.rb",
|
35
|
+
"lib/echor/user.rb",
|
36
|
+
"lib/echor/utils.rb",
|
37
|
+
"spec/echor_spec.rb",
|
38
|
+
"spec/search_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/pedrodelgallego/echor}
|
42
|
+
s.licenses = [%q{MIT}]
|
43
|
+
s.require_paths = [%q{lib}]
|
44
|
+
s.rubygems_version = %q{1.8.1}
|
45
|
+
s.summary = %q{A client for the Echo API}
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<rash>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
55
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
58
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
61
|
+
s.add_dependency(%q<json>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rash>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
71
|
+
s.add_dependency(%q<json>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rash>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
74
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
75
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
77
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/lib/echor.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "json"
|
3
|
+
require "echor/configuration"
|
4
|
+
require "echor/api"
|
5
|
+
require "echor/backplane"
|
6
|
+
require "echor/client"
|
7
|
+
require "echor/search"
|
8
|
+
require "echor/user"
|
9
|
+
require "echor/utils"
|
10
|
+
|
11
|
+
module Echo
|
12
|
+
extend Configuration
|
13
|
+
|
14
|
+
# Alias for Echo::Client.new
|
15
|
+
#
|
16
|
+
# @return [Echo::Client]
|
17
|
+
def self.client(options={})
|
18
|
+
Echo::Client.new(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delegate to Echo::Client
|
22
|
+
def self.method_missing(method, *args, &block)
|
23
|
+
return super unless client.respond_to?(method)
|
24
|
+
client.send(method, *args, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.respond_to?(method, include_private = false)
|
28
|
+
client.respond_to?(method, include_private) || super(method, include_private)
|
29
|
+
end
|
30
|
+
end
|
data/lib/echor/api.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Echo
|
2
|
+
# @private
|
3
|
+
class API
|
4
|
+
# @private
|
5
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
6
|
+
# Creates a new API
|
7
|
+
def initialize(options={})
|
8
|
+
options = Echo.options.merge(options)
|
9
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
10
|
+
send("#{key}=", options[key])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Echo
|
2
|
+
class Backplane < API
|
3
|
+
include HTTParty
|
4
|
+
headers 'Content-Type' => 'application/x-www-urlencoded'
|
5
|
+
|
6
|
+
def initialize(channel, options={})
|
7
|
+
self.class.debug_output $stdout if Echo.debug
|
8
|
+
self.class.base_uri "http://api.echoenabled.com/v1/"
|
9
|
+
self.class.basic_auth Echo.user, Echo.password
|
10
|
+
|
11
|
+
@channel = channel
|
12
|
+
end
|
13
|
+
|
14
|
+
# Log in the user in Backplane
|
15
|
+
#
|
16
|
+
# @params [Hash] the configuration values that should be send to
|
17
|
+
# the echo server
|
18
|
+
# config = {
|
19
|
+
# :identityUrl => "http://conferize.com/u/Pdegallego",
|
20
|
+
# :source => "http://conferize.com",
|
21
|
+
# :username => "Pdelgallego",
|
22
|
+
# :displayName => "Pdelgallego"
|
23
|
+
# }
|
24
|
+
def login(config, echo_id)
|
25
|
+
data = backplane_login_data(config, echo_id, "identity/login")
|
26
|
+
perform_request(data)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Log out the user in Backplane
|
30
|
+
#
|
31
|
+
# @params [Hash] the configuration values that should be send to
|
32
|
+
# the echo server
|
33
|
+
# config = {
|
34
|
+
# :identityUrl => "http://conferize.com/u/Pdegallego",
|
35
|
+
# :source => "http://conferize.com",
|
36
|
+
# :username => "Pdelgallego",
|
37
|
+
# :displayName => "Pdelgallego"
|
38
|
+
# }
|
39
|
+
def logout(config, echo_id)
|
40
|
+
data = backplane_login_data(config, echo_id, "identity/logout")
|
41
|
+
perform_request(data)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def perform_request(data)
|
46
|
+
JSON.parse(`curl -u #{Echo.user}:#{Echo.password} --data-binary '#{data}' #{@channel}`)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create the json structure that Echo will consume.
|
50
|
+
#
|
51
|
+
# @params [String] Each user has associated an echo id that is
|
52
|
+
# the one that should be use to login/logout
|
53
|
+
#
|
54
|
+
# @param [String] The action indicates if the user is logging in
|
55
|
+
# or loogging out
|
56
|
+
def backplane_login_data(config, echo_id, action)
|
57
|
+
data = [{"type" => action, "source" => config[:source],"payload"=>{"context"=>config[:source],"identities"=>{"entry"=>{"accounts"=>[{"identityUrl" => config[:identityUrl],"username"=>config[:username]}],"displayName"=>config[:displayName],"id"=>echo_id},"itemsPerPage"=>1,"startIndex"=>0,"totalResults"=>1}}}].to_json
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/echor/client.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Echo
|
2
|
+
class Client < API
|
3
|
+
include HTTParty
|
4
|
+
headers 'Content-Type' => 'application/x-www-urlencoded'
|
5
|
+
|
6
|
+
# @param [Hash] with options
|
7
|
+
# - debug. Print the raw request and response of the network
|
8
|
+
# calls to echo
|
9
|
+
def initialize(options={})
|
10
|
+
self.class.debug_output $stdout if Echo.debug
|
11
|
+
self.class.base_uri "#{Echo.endpoint}/submit"
|
12
|
+
self.class.basic_auth Echo.user, Echo.password
|
13
|
+
end
|
14
|
+
|
15
|
+
def submit(content)
|
16
|
+
self.class.post( "https://api.echoenabled.com/v1/submit", :query => {:content => content})
|
17
|
+
end
|
18
|
+
|
19
|
+
def tweet_to_xml(status)
|
20
|
+
template = ERB.new(Echo.Templates.TWITTER_XML_TEMPLATE)
|
21
|
+
template.result(binding)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Echo
|
2
|
+
module Configuration
|
3
|
+
# An array of valid keys in the options hash when configuring a {Echo::API}
|
4
|
+
VALID_OPTIONS_KEYS = [
|
5
|
+
:endpoint,
|
6
|
+
:format,
|
7
|
+
:debug,
|
8
|
+
:user,
|
9
|
+
:password,
|
10
|
+
:backplane_user,
|
11
|
+
:backplane_password,
|
12
|
+
:search_endpoint].freeze
|
13
|
+
|
14
|
+
# An array of valid request/response formats
|
15
|
+
#
|
16
|
+
# @note Not all methods support the XML format.
|
17
|
+
VALID_FORMATS = [
|
18
|
+
:json,
|
19
|
+
:xml].freeze
|
20
|
+
|
21
|
+
# By default, don't set an application key
|
22
|
+
DEFAULT_CONSUMER_KEY = nil
|
23
|
+
|
24
|
+
# By default, don't set an application secret
|
25
|
+
DEFAULT_CONSUMER_SECRET = nil
|
26
|
+
|
27
|
+
# The endpoint that will be used to connect if none is set
|
28
|
+
#
|
29
|
+
# @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version, or use a Echo-compatible endpoint.
|
30
|
+
DEFAULT_ENDPOINT = 'http://api.echoenabled.com/v1'.freeze
|
31
|
+
|
32
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
33
|
+
#
|
34
|
+
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
35
|
+
DEFAULT_FORMAT = :json
|
36
|
+
|
37
|
+
# By default, don't set a user oauth token
|
38
|
+
DEFAULT_OAUTH_TOKEN = nil
|
39
|
+
|
40
|
+
# By default, don't set a user oauth secret
|
41
|
+
DEFAULT_OAUTH_TOKEN_SECRET = nil
|
42
|
+
|
43
|
+
# By default, don't use a proxy server
|
44
|
+
DEFAULT_PROXY = nil
|
45
|
+
|
46
|
+
# The search endpoint that will be used to connect if none is set
|
47
|
+
#
|
48
|
+
# @note This is configurable in case you want to use HTTP instead of HTTPS or use a Echo-compatible endpoint.
|
49
|
+
# @see http://status.net/wiki/Echo-compatible_API
|
50
|
+
DEFAULT_SEARCH_ENDPOINT = 'https://search.echo.com/'.freeze
|
51
|
+
|
52
|
+
# The default user for basic authoriation
|
53
|
+
DEFAULT_USER = nil
|
54
|
+
|
55
|
+
# The default password for basic authorization
|
56
|
+
DEFAULT_PASSWORD = nil
|
57
|
+
|
58
|
+
# @private
|
59
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
60
|
+
|
61
|
+
# When this module is extended, set all configuration options to their default values
|
62
|
+
def self.extended(base)
|
63
|
+
base.reset
|
64
|
+
end
|
65
|
+
|
66
|
+
# Convenience method to allow configuration options to be set in a block
|
67
|
+
def configure
|
68
|
+
yield self
|
69
|
+
end
|
70
|
+
|
71
|
+
# Create a hash of options and their values
|
72
|
+
def options
|
73
|
+
options = {}
|
74
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
|
75
|
+
options
|
76
|
+
end
|
77
|
+
|
78
|
+
# Reset all configuration options to defaults
|
79
|
+
def reset
|
80
|
+
self.debug = false
|
81
|
+
self.endpoint = DEFAULT_ENDPOINT
|
82
|
+
self.format = DEFAULT_FORMAT
|
83
|
+
self.search_endpoint = DEFAULT_SEARCH_ENDPOINT
|
84
|
+
self.user = DEFAULT_USER
|
85
|
+
self.password = DEFAULT_PASSWORD
|
86
|
+
self
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/echor/search.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Echo
|
2
|
+
class Search < API
|
3
|
+
include HTTParty
|
4
|
+
debug_output $stdout
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
self.class.class_eval do
|
8
|
+
base_uri Echo.endpoint
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
alias :api_endpoint :search_endpoint
|
13
|
+
|
14
|
+
def build_query(options)
|
15
|
+
raise ArgumentError unless options[:q]
|
16
|
+
raise ArgumentError unless Echo.user
|
17
|
+
|
18
|
+
options[:appkey] = Echo.user
|
19
|
+
|
20
|
+
"/search?#{options.to_query}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch(options={})
|
24
|
+
self.class.get(build_query(options))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/echor/user.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Echo
|
2
|
+
class User < API
|
3
|
+
include HTTParty
|
4
|
+
headers 'Content-Type' => 'application/x-www-urlencoded'
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
self.class.debug_output $stdout if Echo.debug
|
8
|
+
self.class.base_uri "https://api.echoenabled.com/v1/users/"
|
9
|
+
self.class.basic_auth Echo.user, Echo.password
|
10
|
+
end
|
11
|
+
|
12
|
+
def who_am_i(options={})
|
13
|
+
options[:appkey] = Echo.user
|
14
|
+
raise ArgumentError, "You need to provide a sessionID" unless options[:sessionID]
|
15
|
+
raise ArgumentError, "You need to setup Echo.user" unless Echo.user
|
16
|
+
self.class.get("/whoami?#{options.to_query}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(options={})
|
20
|
+
options[:appkey] = Echo.user
|
21
|
+
raise ArgumentError, "You need to provide a sessionID" unless options[:sessionID]
|
22
|
+
raise ArgumentError, "You need to provide a indetifyURL" unless options[:identityURL]
|
23
|
+
raise ArgumentError, "You need to setup Echo.user" unless Echo.user
|
24
|
+
self.class.get("/get?#{options.to_query}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(content, options={})
|
28
|
+
self.class.post( "https://api.echoenabled.com/v1/users/update", :query => content)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/echor/utils.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
unless (Object.respond_to? :to_query)
|
2
|
+
class Object
|
3
|
+
def to_query(key)
|
4
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
5
|
+
"#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(to_s)}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
unless defined?(ActiveSupport::CoreExtensions::Hash)
|
11
|
+
class Hash
|
12
|
+
def to_query(namespace = nil)
|
13
|
+
collect do |key, value|
|
14
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
15
|
+
end.sort * '&'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/spec/echor_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Echo do
|
4
|
+
describe "Configuration" do
|
5
|
+
before :each do
|
6
|
+
Echo.configure do |config|
|
7
|
+
config.user = "pedro"
|
8
|
+
config.password = "secret"
|
9
|
+
config.debug = true
|
10
|
+
config.backplane_user = "pedro_bp"
|
11
|
+
config.backplane_password = "secret_bp"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
it "should be able to config the consumer_key" do
|
15
|
+
Echo.debug.should be_true
|
16
|
+
end
|
17
|
+
it "should be able to config the user" do
|
18
|
+
Echo.user.should == "pedro"
|
19
|
+
end
|
20
|
+
it "should be able to config the password" do
|
21
|
+
Echo.password.should == "secret"
|
22
|
+
end
|
23
|
+
it "should be able to config the backplane user" do
|
24
|
+
Echo.backplane_user.should == "pedro_bp"
|
25
|
+
end
|
26
|
+
it "should be able to config the backplane password" do
|
27
|
+
Echo.backplane_password.should == "secret_bp"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/search_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# require 'helper'
|
2
|
+
|
3
|
+
describe Echo::Search do
|
4
|
+
|
5
|
+
describe "Mandatory parameters" do
|
6
|
+
before :each do
|
7
|
+
@search = Echo::Search.new
|
8
|
+
end
|
9
|
+
it "should fails if not query is provided" do
|
10
|
+
lambda{ @search.build_query }.should raise_error { ArgumentError }
|
11
|
+
end
|
12
|
+
it "should fails if not apikey is provided" do
|
13
|
+
lambda{
|
14
|
+
@search.build_query :q => "scope:something"
|
15
|
+
}.should raise_error {ArgumentError}
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Echo.reset
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Queries" do
|
24
|
+
before :each do
|
25
|
+
Echo.configure do
|
26
|
+
Echo.configure do |config|
|
27
|
+
config.user = "test.aboutecho"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@search = Echo::Search.new
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "Raw Queries" do
|
34
|
+
it "should create a basic query" do
|
35
|
+
@search.build_query({
|
36
|
+
:q => "scope: http://example.com/*"
|
37
|
+
}).should == "/search?appkey=test.aboutecho&q=scope%3A+http%3A%2F%2Fexample.com%2F%2A"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "API" do
|
42
|
+
it "should find only tagged elements"
|
43
|
+
it "should find not tagged elements"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'echor'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: echor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pedro Del Gallego
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
prerelease: false
|
32
|
+
requirement: *id001
|
33
|
+
name: httparty
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
requirement: *id002
|
47
|
+
name: json
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
type: :runtime
|
59
|
+
prerelease: false
|
60
|
+
requirement: *id003
|
61
|
+
name: rash
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 3
|
72
|
+
- 0
|
73
|
+
version: 2.3.0
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
requirement: *id004
|
77
|
+
name: rspec
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 7
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
- 6
|
88
|
+
- 0
|
89
|
+
version: 0.6.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
requirement: *id005
|
93
|
+
name: yard
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 23
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 0
|
104
|
+
- 0
|
105
|
+
version: 1.0.0
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
requirement: *id006
|
109
|
+
name: bundler
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ~>
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 15
|
117
|
+
segments:
|
118
|
+
- 1
|
119
|
+
- 6
|
120
|
+
- 0
|
121
|
+
version: 1.6.0
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
requirement: *id007
|
125
|
+
name: jeweler
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
type: :development
|
137
|
+
prerelease: false
|
138
|
+
requirement: *id008
|
139
|
+
name: rcov
|
140
|
+
description: " Echo ruby wrappper "
|
141
|
+
email: pedro.delgallego@gmail.com
|
142
|
+
executables: []
|
143
|
+
|
144
|
+
extensions: []
|
145
|
+
|
146
|
+
extra_rdoc_files:
|
147
|
+
- LICENSE.txt
|
148
|
+
- README.rdoc
|
149
|
+
files:
|
150
|
+
- .document
|
151
|
+
- .rspec
|
152
|
+
- Gemfile
|
153
|
+
- Gemfile.lock
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.rdoc
|
156
|
+
- Rakefile
|
157
|
+
- VERSION
|
158
|
+
- echor.gemspec
|
159
|
+
- lib/echor.rb
|
160
|
+
- lib/echor/api.rb
|
161
|
+
- lib/echor/backplane.rb
|
162
|
+
- lib/echor/client.rb
|
163
|
+
- lib/echor/configuration.rb
|
164
|
+
- lib/echor/search.rb
|
165
|
+
- lib/echor/user.rb
|
166
|
+
- lib/echor/utils.rb
|
167
|
+
- spec/echor_spec.rb
|
168
|
+
- spec/search_spec.rb
|
169
|
+
- spec/spec_helper.rb
|
170
|
+
homepage: http://github.com/pedrodelgallego/echor
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
hash: 3
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
version: "0"
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
none: false
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
hash: 3
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
version: "0"
|
196
|
+
requirements: []
|
197
|
+
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 1.8.1
|
200
|
+
signing_key:
|
201
|
+
specification_version: 3
|
202
|
+
summary: A client for the Echo API
|
203
|
+
test_files: []
|
204
|
+
|