listingcheck_api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 listingcheck_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Joopp BV / ListingCheck
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.
@@ -0,0 +1,52 @@
1
+ # ListingcheckApi
2
+
3
+ Ruby API to use the ListingCheck REST API.
4
+
5
+ ListingCheck allows you to scan the Internet for listings of a business. Multiple countries are supported. See for example http://www.goedvermeld.nl, for more information check http://www.listingcheck.com.
6
+
7
+ For more information on this Gem contact joost@joopp.com.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'listingcheck_api'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install listingcheck_api
22
+
23
+ ## Usage
24
+
25
+ api = ListingcheckApi::Client.new(:auth_token => 'your_ubersecret_token')
26
+
27
+ Locally setup a new Scan to peform:
28
+
29
+ place = ListingcheckApi::Place.new(:name => 'Tam Tam', :phone => '015-7502000', :address => 'Patrijsweg 80', :city => 'Rijswijk')
30
+ scan = ListingcheckApi::Scan.new(:scan_group => 'restaurants', :place_attributes => place)
31
+
32
+ Send API call to create the scan and next perform it.
33
+
34
+ api.create_scan(scan)
35
+ api.perform_scan
36
+
37
+ You will receive the Scan with a unique access_token and all matched listings.
38
+
39
+ ## Supported Listings
40
+
41
+ We currently support (among others) listings from:
42
+ Facebook Places, Twitter Places, Foursquare Venues, Gouden Gids België (Yellow Pages Belgium), SaySo, Qype, Tupalo (disabled), LinkedIn (disabled), Yell, Telefoonboek.nl, TomTom Places, Yelp, Zoekned.nl, Herold.at, Iens Belgium/Netherlands, Google Plus, Dinnersite, Das Örtliche, Local.ch, Infobel, Eet.nu, Cityplug, GelbeSeiten, Souschef, Resto.be, ..
43
+
44
+ New sites are added constantly, please contact us for more information.
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,122 @@
1
+ require "listingcheck_api/version"
2
+
3
+ require 'api_smith'
4
+
5
+ # api = ListingcheckApi::Client.new(:auth_token => 'your_ubersecret_token', :base_uri => '..')
6
+ # place = ListingcheckApi::Place.new(:name => 'Bridges', :phone => '020-5553560', :address => 'Oudezijds Voorburgwal 197', :city => 'Amsterdam')
7
+ # scan = ListingcheckApi::Scan.new(:scan_group => 'restaurants', :place_attributes => place)
8
+ # api.create_scan(scan)
9
+ # api.post('listings_scans.json', {:extra_query => {:listings_scan => scan}})
10
+ # api.perform_scan
11
+ # api.listing('facebook_places_listing', 142709532406955)
12
+ # api.create_listing('facebook_places_listing', )
13
+ module ListingcheckApi
14
+
15
+ class Listing < APISmith::Smash
16
+ property :type
17
+ property :uid
18
+ property :url
19
+ property :name
20
+ property :phone
21
+ property :full_address
22
+ property :country_code
23
+ property :lat
24
+ property :lng
25
+ end
26
+
27
+ class Place < APISmith::Smash
28
+ # Needed to create new Place for Scan
29
+ property :name, :required => true
30
+ property :phone, :required => true
31
+ property :address, :required => true
32
+ property :city, :required => true
33
+
34
+ # Filled in
35
+ property :country_code
36
+ property :lat
37
+ property :lng
38
+ end
39
+
40
+ class Scan < APISmith::Smash
41
+ property :access_token
42
+ property :scan_group
43
+ # property :email
44
+ property :place, :transformer => Place
45
+ property :place_attributes, :transformer => Place
46
+
47
+ property :matched_listings, :transformer => Listing
48
+ property :error_listing_types
49
+
50
+ def matched_listing_types
51
+ matched_listings.collect(&:type)
52
+ end
53
+
54
+ # FIXME: What is the proper way to do this?
55
+ def scan!(client)
56
+ client.perform_scan(self.access_token)
57
+ end
58
+
59
+ end
60
+
61
+ class Client
62
+
63
+ include APISmith::Client
64
+
65
+ attr_reader :auth_token, :version
66
+
67
+ # Options:
68
+ # * :auth_token - Your ListingCheck Authentication token (API)
69
+ # * :version - Version (defaults to 1)
70
+ # * :base_uri - Set if you want to use development version
71
+ def initialize(options = {})
72
+ @auth_token = options[:auth_token]
73
+ @version = options[:version] || '1'
74
+
75
+ self.class.base_uri(options[:base_uri] || 'api.listingscan.com')
76
+ self.class.endpoint("api/v#{version}")
77
+
78
+ add_query_options!(:auth_token => auth_token)
79
+ end
80
+
81
+ # Opens a (Listing)Scan.
82
+ def scan(access_token)
83
+ self.get("listings_scans/#{access_token}.json", :transform => Scan)
84
+ end
85
+
86
+ # Creates a new Scan. Requires a associated Place.
87
+ def create_scan(scan)
88
+ self.post('listings_scans.json', {:extra_query => {:listings_scan => scan}, :transform => Scan})
89
+ end
90
+
91
+ # Performs a Scan (scans for Listings).
92
+ def perform_scan(access_token)
93
+ self.put("listings_scans/#{access_token}/scan.json", :transform => Scan)
94
+ end
95
+
96
+ # Gets a existing Listing of a particular type.
97
+ # listing('facebook_places_listing', 142709532406955)
98
+ def listing(type, uid)
99
+ self.get("listing_types/#{type}/listings/#{uid}.json", :transform => Listing)
100
+ end
101
+
102
+ # Gets or creates a new Listing of a particular type.
103
+ def create_listing(type, uid)
104
+ self.put("listing_types/#{type}/listings/#{uid}.json", :transform => Listing)
105
+ end
106
+
107
+ def check_response_errors(response)
108
+ # In 2XX range is success otherwise it's probably error (3XX redirects range is handled by HTTParty).
109
+ # In case of error we lookup error class or default to ApiError.
110
+ if not (200..299).include?(response.code)
111
+ raise "Got HTTP code #{response.code} (#{response.message}) from API."
112
+ end
113
+
114
+ # Check JSON for error
115
+ # if response.parsed_response.is_a?(Hash) and (error = response.parsed_response['error'])
116
+ # raise error
117
+ # end
118
+ end
119
+
120
+ end # Client
121
+
122
+ end
@@ -0,0 +1,3 @@
1
+ module ListingcheckApi
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/listingcheck_api/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Joost Hietbrink"]
6
+ gem.email = ["joost@joopp.com"]
7
+ gem.description = %q{Ruby API to use the ListingCheck REST API.}
8
+ gem.summary = %q{Ruby API to use the ListingCheck REST API.}
9
+ gem.homepage = "http://www.listingcheck.com"
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 = "listingcheck_api"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ListingcheckApi::VERSION
17
+
18
+ gem.add_dependency('api_smith')
19
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: listingcheck_api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Joost Hietbrink
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-10-11 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: api_smith
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description: Ruby API to use the ListingCheck REST API.
33
+ email:
34
+ - joost@joopp.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - .gitignore
43
+ - Gemfile
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - lib/listingcheck_api.rb
48
+ - lib/listingcheck_api/version.rb
49
+ - listingcheck_api.gemspec
50
+ has_rdoc: true
51
+ homepage: http://www.listingcheck.com
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Ruby API to use the ListingCheck REST API.
80
+ test_files: []
81
+