threetaps_client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in threetaps_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Phong Nguyen
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,64 @@
1
+ # ThreetapsClient
2
+
3
+ A very simple Rest Client for 3taps API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'threetaps_client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install threetaps_client
18
+
19
+ ## Usage
20
+
21
+ Setup API key:
22
+
23
+ ThreetapsClient.api_key = <your-api-key>
24
+
25
+ Use Search API:
26
+
27
+ ThreetapsClient.search :source => 'CRAIG', :location => { :country => 'USA' }
28
+
29
+ Use Polling API:
30
+
31
+ # To start polling from a given point in time
32
+ ThreetapsClient.anchor Time.now.to_i
33
+
34
+ # Retrieves a set of new postings from the database
35
+ ThreetapsClient.poll
36
+ ThreetapsClient.poll(640587080)
37
+ ThreetapsClient.poll('640587080')
38
+ ThreetapsClient.poll :anchor => '640587080', :source => 'CRAIG', :location => { :country => 'USA' }
39
+
40
+ Use Reference API:
41
+
42
+ # To obtain a list of data sources
43
+ ThreetapsClient.data_sources
44
+
45
+ # To obtain a list of category groups
46
+ ThreetapsClient.category_groups
47
+
48
+ # To obtain a list of categories
49
+ ThreetapsClient.categories
50
+
51
+ # To obtain a list of locations by level
52
+ # level can be 'country'|'state'|'metro'|'region'|'county'|'city'|'locality'|'zipcode'
53
+ ThreetapsClient.locations(level)
54
+
55
+ # The find the details of a single location based on its 3taps location code
56
+ ThreetapsClient.lookup_location(code)
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( http://github.com/phongnh/threetaps_client/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ return if {}.respond_to?(:extract_options!)
2
+
3
+ class Array
4
+ def extract_options!
5
+ self.last.is_a?(Hash) ? self.pop : {}
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ class Hash
2
+ # Returns a "flatten" hash representation of the receiver:
3
+ #
4
+ # { :source => 'CRAIG', :location => { :country => 'USA' } }.flatten
5
+ # # => { :source => 'CRAIG', :"location.country" => 'USA' }
6
+ #
7
+ # { :param => 1, :nested => { :param => 2, :nested => { :param => 2 } } }.flatten
8
+ # # => { :param => 1, :"nested.param" => 2, :"nested.nested.param" => 2}
9
+ #
10
+ # An optional prefix can be passed to enclose the key names:
11
+ #
12
+ # { :country => 'USA', :state => 'CA' }.flatten('location')
13
+ # # => { :"location.country" => 'USA', :"location.state" => 'CA' }
14
+ def flatten(prefix=nil)
15
+ prefix = "#{prefix}." if prefix
16
+ inject({}) do |hash, (key, value)|
17
+ if value.is_a?(Hash)
18
+ hash.merge! value.flatten("#{prefix}#{key}")
19
+ else
20
+ hash[:"#{prefix}#{key}"] = value
21
+ end
22
+ hash
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ class String
2
+ # Parses a JSON string (JavaScript Object Notation) into a hash.
3
+ #
4
+ # "{\"success\":true,\"anchor\":640503449}".decode_json
5
+ # # => { "success": true, "anchor":640503449 }
6
+ def decode_json
7
+ JSON(self)
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'core_ext', '*.rb')].sort.each do |file|
2
+ require "threetaps_client/core_ext/#{File.basename(file, '*.rb')}"
3
+ end
@@ -0,0 +1,3 @@
1
+ module ThreetapsClient
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,82 @@
1
+ require 'json'
2
+ require 'restclient'
3
+ require "threetaps_client/version"
4
+ require "threetaps_client/core_ext"
5
+
6
+ module ThreetapsClient
7
+ extend self
8
+
9
+ DOMAIN = '3taps.com'
10
+ SEARCH_END_POINT = "http://search.#{DOMAIN}"
11
+ POLLING_END_POINT = "http://polling.#{DOMAIN}"
12
+ REFERENCE_END_POINT = "http://reference.#{DOMAIN}"
13
+
14
+ ANCHOR_URL = "#{POLLING_END_POINT}/anchor"
15
+ POLL_URL = "#{POLLING_END_POINT}/poll"
16
+
17
+ DATA_SOURCES_URL = "#{REFERENCE_END_POINT}/sources"
18
+ CATEGORY_GROUPS_URL = "#{REFERENCE_END_POINT}/category_groups"
19
+ CATEGORIES_URL = "#{REFERENCE_END_POINT}/categories"
20
+ LOCATIONS_URL = "#{REFERENCE_END_POINT}/locations"
21
+ LOCATION_LOOKUP_URL = "#{REFERENCE_END_POINT}/locations/lookup"
22
+
23
+ attr_accessor :api_key
24
+
25
+ def search(criteria={})
26
+ request SEARCH_END_POINT, criteria
27
+ end
28
+
29
+ def anchor(timestamp=Time.now.to_i)
30
+ request ANCHOR_URL, :timestamp => timestamp
31
+ end
32
+
33
+ def poll(*args)
34
+ criteria = args.extract_options!
35
+ anchor = args.first || criteria[:anchor]
36
+ anchor = self.anchor['anchor'] if anchor.nil?
37
+ request POLL_URL, criteria.merge(:anchor => anchor)
38
+ end
39
+
40
+ def data_sources
41
+ request DATA_SOURCES_URL
42
+ end
43
+
44
+ def category_groups
45
+ request CATEGORY_GROUPS_URL
46
+ end
47
+
48
+ def categories
49
+ request CATEGORIES_URL
50
+ end
51
+
52
+ def locations(level='country')
53
+ request LOCATIONS_URL, :level => level
54
+ end
55
+
56
+ def lookup_location(code)
57
+ request LOCATION_LOOKUP_URL, :code => code
58
+ end
59
+
60
+ def retvals
61
+ %w[
62
+ id account_id source category category_group
63
+ location external_id external_url heading body
64
+ timestamp expires language price currency
65
+ images annotations status immortal deleted
66
+ ].join(',')
67
+ end
68
+
69
+ def default_params
70
+ { :auth_token => api_key, :retvals => retvals }
71
+ end
72
+
73
+ def request(url, params={})
74
+ params = default_params.merge params.flatten
75
+ response = RestClient.get url, :params => params, :accept => :json
76
+ response.decode_json
77
+ end
78
+
79
+ def log=(io)
80
+ RestClient.log = io
81
+ end
82
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'threetaps_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "threetaps_client"
8
+ spec.version = ThreetapsClient::VERSION
9
+ spec.authors = ["Phong Nguyen"]
10
+ spec.email = ["nhphong1406@gmail.com"]
11
+ spec.summary = %q{Ruby Client for 3taps API}
12
+ spec.description = %q{A very simple Rest Client for 3taps API.}
13
+ spec.homepage = "http://github.com/phongnh/threetaps_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", ">= 1.3.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+
25
+ spec.add_dependency "json"
26
+ spec.add_dependency "rest-client", "~> 1.6.7"
27
+ spec.add_dependency "mime-types", "~> 1.25.1"
28
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: threetaps_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Phong Nguyen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2014-03-02 00:00:00 +07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 17
28
+ segments:
29
+ - 1
30
+ - 3
31
+ - 5
32
+ version: 1.3.5
33
+ type: :development
34
+ requirement: *id001
35
+ prerelease: false
36
+ name: bundler
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ requirement: *id002
49
+ prerelease: false
50
+ name: rake
51
+ - !ruby/object:Gem::Dependency
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ requirement: *id003
63
+ prerelease: false
64
+ name: pry
65
+ - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :runtime
76
+ requirement: *id004
77
+ prerelease: false
78
+ name: json
79
+ - !ruby/object:Gem::Dependency
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ hash: 1
86
+ segments:
87
+ - 1
88
+ - 6
89
+ - 7
90
+ version: 1.6.7
91
+ type: :runtime
92
+ requirement: *id005
93
+ prerelease: false
94
+ name: rest-client
95
+ - !ruby/object:Gem::Dependency
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ hash: 113
102
+ segments:
103
+ - 1
104
+ - 25
105
+ - 1
106
+ version: 1.25.1
107
+ type: :runtime
108
+ requirement: *id006
109
+ prerelease: false
110
+ name: mime-types
111
+ description: A very simple Rest Client for 3taps API.
112
+ email:
113
+ - nhphong1406@gmail.com
114
+ executables: []
115
+
116
+ extensions: []
117
+
118
+ extra_rdoc_files: []
119
+
120
+ files:
121
+ - .gitignore
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - lib/threetaps_client.rb
127
+ - lib/threetaps_client/core_ext.rb
128
+ - lib/threetaps_client/core_ext/array.rb
129
+ - lib/threetaps_client/core_ext/hash.rb
130
+ - lib/threetaps_client/core_ext/string.rb
131
+ - lib/threetaps_client/version.rb
132
+ - threetaps_client.gemspec
133
+ has_rdoc: true
134
+ homepage: http://github.com/phongnh/threetaps_client
135
+ licenses:
136
+ - MIT
137
+ post_install_message:
138
+ rdoc_options: []
139
+
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ requirements: []
161
+
162
+ rubyforge_project:
163
+ rubygems_version: 1.6.2
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Ruby Client for 3taps API
167
+ test_files: []
168
+