three_taps_api 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/three_taps_api.rb +6 -0
- data/lib/three_taps_api/base.rb +25 -0
- data/lib/three_taps_api/location.rb +13 -0
- data/lib/three_taps_api/reference.rb +34 -0
- data/lib/three_taps_api/search.rb +47 -0
- data/lib/three_taps_api/valid_parameters.rb +20 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 32a2bb227118ec96558aa7daefab93f5980af0dc
|
|
4
|
+
data.tar.gz: 62e5b053d3cef593824ad224951f705894b6d59a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5e826298100046ddfafbb7f7d66b388461b9cfec8d23786f04b34f420ddfa9cf60ae2f57bc426c580c5a43c1d203a97cb0c8c69bbeea074d636b839076363005
|
|
7
|
+
data.tar.gz: 8a6bf6d85c18c24cb0bd4e23bdea20114696bb61b146c19aab677c307e00e84db04c950772974690679e078f4e3851221125fdee105ac0bfd0d47c6afbdacef3
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require_relative 'location'
|
|
2
|
+
|
|
3
|
+
module ThreeTapsAPI
|
|
4
|
+
def self.rec_hash_to_openstruct(hash)
|
|
5
|
+
raise TypeError if not hash.is_a? Hash
|
|
6
|
+
hash = hash.map { |k, v| [k, v.is_a?(Hash) ? rec_hash_to_openstruct(v) : v] }
|
|
7
|
+
OpenStruct.new Hash[hash]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class Base
|
|
11
|
+
include HTTParty
|
|
12
|
+
base_uri '3taps.com'
|
|
13
|
+
@@api_key = ENV['THREE_TAPS_API_KEY']
|
|
14
|
+
attr_reader :results
|
|
15
|
+
|
|
16
|
+
def self.api_key
|
|
17
|
+
@@api_key
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def auth_token_hash
|
|
21
|
+
{ auth_token: self.class.api_key }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ThreeTapsAPI
|
|
2
|
+
# Class for describing the 3taps location in an API-specific way
|
|
3
|
+
class Location
|
|
4
|
+
# Add more attributes as they are tested
|
|
5
|
+
attr_accessor :country, :zipcode
|
|
6
|
+
|
|
7
|
+
def initialize(args)
|
|
8
|
+
args.each do |k, v|
|
|
9
|
+
self.send "#{k}=", v if self.class.method_defined? "#{k}"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require_relative 'base'
|
|
2
|
+
|
|
3
|
+
module ThreeTapsAPI
|
|
4
|
+
class Reference < Base
|
|
5
|
+
base_uri 'reference.3taps.com'
|
|
6
|
+
|
|
7
|
+
def locations(level)
|
|
8
|
+
uri = self.class.base_uri + '/locations'
|
|
9
|
+
@results = self.class.get uri, { query: auth_token_hash.merge({ level: level }) }
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
parsed_response = ThreeTapsAPI.rec_hash_to_openstruct @results.parsed_response
|
|
13
|
+
@reference = parsed_response.send "#{level.to_s}" if parsed_response.success
|
|
14
|
+
rescue TypeError
|
|
15
|
+
p "ThreeTapsAPI::Reference.locations #{level.to_s}: rec_hash_to_openstruct not passed a hash"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def method_missing(name, *args, &block)
|
|
20
|
+
p "#{name} is not a valid parameter." and return if ThreeTapsAPI.invalid_parameter? name
|
|
21
|
+
uri = self.class.base_uri + "/#{name.to_s}"
|
|
22
|
+
@results = self.class.get uri, { query: auth_token_hash }
|
|
23
|
+
|
|
24
|
+
# if it's a valid request,
|
|
25
|
+
# create a get/setter for it
|
|
26
|
+
begin
|
|
27
|
+
parsed_response = ThreeTapsAPI.rec_hash_to_openstruct @results.parsed_response
|
|
28
|
+
@reference = parsed_response.send "#{name.to_s}" if parsed_response.success
|
|
29
|
+
rescue TypeError
|
|
30
|
+
p "ThreeTapsAPI::Reference.locations #{name.to_s}: rec_hash_to_openstruct not passed a hash"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require_relative 'base'
|
|
2
|
+
|
|
3
|
+
module ThreeTapsAPI
|
|
4
|
+
class Search < Base
|
|
5
|
+
base_uri 'search.3taps.com'
|
|
6
|
+
attr_reader :postings
|
|
7
|
+
attr_reader :parameters
|
|
8
|
+
attr_accessor :location
|
|
9
|
+
|
|
10
|
+
def create_getter_and_setter(name)
|
|
11
|
+
get = Proc.new { instance_variable_get "@#{name}" }
|
|
12
|
+
set = Proc.new { |val| instance_variable_set "@#{name}", val; @parameters[name.to_sym] = val }
|
|
13
|
+
self.class.send :define_method, "#{name}", get
|
|
14
|
+
self.class.send :define_method, "#{name}=", set
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(args = {})
|
|
18
|
+
@parameters = args
|
|
19
|
+
@location = Location.new(args.delete(:location) || {})
|
|
20
|
+
@postings = OpenStruct.new
|
|
21
|
+
|
|
22
|
+
#args.delete :location
|
|
23
|
+
|
|
24
|
+
args.each do |k, v|
|
|
25
|
+
create_getter_and_setter k if ThreeTapsAPI.valid_parameter? k.to_s
|
|
26
|
+
self.send "#{k.to_s}=", v
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def search
|
|
31
|
+
opts = {}
|
|
32
|
+
opts.merge!(auth_token_hash)
|
|
33
|
+
.merge!(@parameters)
|
|
34
|
+
@results = self.class.get self.class.base_uri, { query: opts }
|
|
35
|
+
@postings = @results.parsed_response['postings'].map { |p| ThreeTapsAPI.rec_hash_to_openstruct p }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def method_missing(name, *args, &block)
|
|
39
|
+
# TODO: return if not a setter function
|
|
40
|
+
name = name.to_s.chop if name.to_s.reverse[0] == '='
|
|
41
|
+
p "#{name} is not a valid parameter." and return if ThreeTapsAPI.invalid_parameter? name
|
|
42
|
+
@parameters[name.to_sym] = args[0]
|
|
43
|
+
create_getter_and_setter name
|
|
44
|
+
self.send "#{name.to_s}=".to_sym, args[0]
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module ThreeTapsAPI
|
|
2
|
+
@@valid_parameters = %w(category_group category_groups
|
|
3
|
+
category categories radius
|
|
4
|
+
lat long source sources external_id
|
|
5
|
+
heading body text timestamp id
|
|
6
|
+
price currency annotations status
|
|
7
|
+
state has_image has_price include_deleted
|
|
8
|
+
only_deleted location locations)
|
|
9
|
+
def self.valid_parameters
|
|
10
|
+
@@valid_parameters
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.valid_parameter?(str)
|
|
14
|
+
@@valid_parameters.include? str
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.invalid_parameter?(str)
|
|
18
|
+
!self.valid_parameter? str
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: three_taps_api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- John Marinelli
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A simple, lightweight wrapper to call the 3taps API. Requires an authentication
|
|
14
|
+
key from the 3taps service.
|
|
15
|
+
email: john@johnmarinelli.me
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/three_taps_api.rb
|
|
21
|
+
- lib/three_taps_api/base.rb
|
|
22
|
+
- lib/three_taps_api/location.rb
|
|
23
|
+
- lib/three_taps_api/reference.rb
|
|
24
|
+
- lib/three_taps_api/search.rb
|
|
25
|
+
- lib/three_taps_api/valid_parameters.rb
|
|
26
|
+
homepage: http://rubygems.org/gems/three_taps_api
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata: {}
|
|
30
|
+
post_install_message:
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubyforge_project:
|
|
46
|
+
rubygems_version: 2.4.6
|
|
47
|
+
signing_key:
|
|
48
|
+
specification_version: 4
|
|
49
|
+
summary: Wrapper for the 3taps API.
|
|
50
|
+
test_files: []
|