teleportd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/teleportd/config.rb +13 -0
- data/lib/teleportd/request.rb +21 -0
- data/lib/teleportd/search.rb +92 -0
- data/lib/teleportd/version.rb +3 -0
- data/lib/teleportd.rb +11 -0
- data/teleportd.gemspec +23 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nicholas Fine
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Teleportd
|
2
|
+
|
3
|
+
Ruby Wrapper Library for Teleportd API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'teleportd'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install teleportd
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Teleportd
|
2
|
+
class Request
|
3
|
+
def initialize uri
|
4
|
+
@uri = Config.base_url << uri
|
5
|
+
end
|
6
|
+
|
7
|
+
def parsed_response
|
8
|
+
JSON.parse(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def response
|
13
|
+
@response ||= make_request.body_str
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_request
|
17
|
+
Curl::Easy.perform(@uri)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'pry'
|
2
|
+
module Teleportd
|
3
|
+
class Search
|
4
|
+
|
5
|
+
attr_reader :opts
|
6
|
+
|
7
|
+
def initialize opts={}
|
8
|
+
@opts = opts
|
9
|
+
@request = Request.new(request_uri)
|
10
|
+
end
|
11
|
+
|
12
|
+
def result
|
13
|
+
@request.parsed_response
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def request_uri
|
18
|
+
available_filters.each_with_object(base_request_uri) do |filter, uri|
|
19
|
+
uri << "&#{self.send(filter)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_request_uri
|
24
|
+
"/search?user_key=#{Config.api_key}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def available_filters
|
28
|
+
[:location, :textual_search, :time_period, :size_filter, :from_filter, :sort_filter].each_with_object([]) do |filter, available|
|
29
|
+
available << filter unless self.send(filter).nil?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_location?
|
34
|
+
loc = opts[:location]
|
35
|
+
!!loc && loc.has_key?(:latitude) && loc.has_key(:longitude) && loc.has_key(:vertical) && loc.has_key(:horizontal)
|
36
|
+
end
|
37
|
+
|
38
|
+
def location
|
39
|
+
return nil unless has_location?
|
40
|
+
loc = opts[:location]
|
41
|
+
"loc=[#{loc[:latitude]},#{loc[:longitude]},#{loc[:vertical]},#{loc[:horizontal]}]"
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_textual_search?
|
45
|
+
opts.has_key?(:textual_search)
|
46
|
+
end
|
47
|
+
|
48
|
+
def textual_search
|
49
|
+
return nil unless has_textual_search?
|
50
|
+
"str=#{URI.encode(opts[:textual_search])}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def has_time_search?
|
54
|
+
time_period = opts[:time_period]
|
55
|
+
!!time_period && time_period.has_key?(:start_time) && time_period.has_key?(:end_time)
|
56
|
+
end
|
57
|
+
|
58
|
+
def time_period
|
59
|
+
return nil unless has_time_search?
|
60
|
+
begin_period = opts[:time_period][:start_time].to_i
|
61
|
+
end_period = opts[:time_period][:end_time].to_i
|
62
|
+
"period=[#{begin_period},#{end_period}]"
|
63
|
+
end
|
64
|
+
|
65
|
+
def has_size_filter?
|
66
|
+
opts.has_key?(:size)
|
67
|
+
end
|
68
|
+
|
69
|
+
def size_filter
|
70
|
+
return nil unless has_size_filter?
|
71
|
+
"size=#{opts[:size]}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def has_from_filter?
|
75
|
+
opts.has_key?(:from)
|
76
|
+
end
|
77
|
+
|
78
|
+
def from_filter
|
79
|
+
return nil unless has_from_filter?
|
80
|
+
"from=#{opts[:from]}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def has_sort_filter?
|
84
|
+
opts.has_key?(:sort) && opts[:sort] == ('relevance' || 'recency')
|
85
|
+
end
|
86
|
+
|
87
|
+
def sort_filter
|
88
|
+
return nil unless has_sort_filter?
|
89
|
+
"sort=#{opts[:sort]}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/teleportd.rb
ADDED
data/teleportd.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/teleportd/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Nicholas Fine"]
|
6
|
+
gem.email = ["nicholas.fine@gmail.com"]
|
7
|
+
gem.description = %q{Ruby Wrapper Library for Teleportd API}
|
8
|
+
gem.summary = %q{Ruby Wrapper Library for Teleportd API}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "teleportd"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Teleportd::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'json', '~> 1.7.1'
|
19
|
+
gem.add_runtime_dependency 'active_support'
|
20
|
+
gem.add_runtime_dependency 'i18n'
|
21
|
+
gem.add_runtime_dependency 'curb'
|
22
|
+
gem.add_development_dependency 'pry'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teleportd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicholas Fine
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &15312040 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.7.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15312040
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: active_support
|
27
|
+
requirement: &15311460 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *15311460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: i18n
|
38
|
+
requirement: &15310740 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *15310740
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: curb
|
49
|
+
requirement: &15310120 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *15310120
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: pry
|
60
|
+
requirement: &15309460 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *15309460
|
69
|
+
description: Ruby Wrapper Library for Teleportd API
|
70
|
+
email:
|
71
|
+
- nicholas.fine@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/teleportd.rb
|
82
|
+
- lib/teleportd/config.rb
|
83
|
+
- lib/teleportd/request.rb
|
84
|
+
- lib/teleportd/search.rb
|
85
|
+
- lib/teleportd/version.rb
|
86
|
+
- teleportd.gemspec
|
87
|
+
homepage: ''
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.15
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Ruby Wrapper Library for Teleportd API
|
111
|
+
test_files: []
|