yp 0.0.1alpha

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.
Files changed (9) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +2 -0
  6. data/lib/yp/version.rb +3 -0
  7. data/lib/yp.rb +57 -0
  8. data/yp.gemspec +21 -0
  9. metadata +89 -0
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 yp.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Allen Walker
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
+ # Yp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'yp'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install yp
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,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/yp/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Yp
2
+ VERSION = "0.0.1alpha"
3
+ end
data/lib/yp.rb ADDED
@@ -0,0 +1,57 @@
1
+ require "yp/version"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+ require "json"
5
+
6
+ module Yp
7
+
8
+ # Yp::Client.new(api_key: "YOUR_API_KEY")
9
+
10
+ class Client
11
+ API_URL = "http://api2.yp.com"
12
+
13
+ SEARCH_PATH = "listings/v1/search"
14
+ DETAILS_PATH = "listings/v1/details"
15
+
16
+ def initialize(options={})
17
+ @api_key = options[:api_key]
18
+ end
19
+
20
+ # e.g. client.search(searchloc: "94109", term: "kayak")
21
+ # http://api2.yp.com/listings/v1/search
22
+ def search(options={})
23
+ response = connection.get do |req|
24
+ req.url SEARCH_PATH, options
25
+ end
26
+
27
+ JSON.parse(response.body)['searchResult']['searchListings']
28
+ end
29
+
30
+ # e.g. client.details("30624356")
31
+ # http://api2.yp.com/listings/v1/details?listingid=30624356&key=xxxxxxxxxx
32
+ def details(listingid)
33
+ response = connection.get do |req|
34
+ req.url DETAILS_PATH, {listingid: listingid}
35
+ end
36
+
37
+ JSON.parse(response.body)['listingsDetailsResult']['listingsDetails']
38
+ end
39
+
40
+ private
41
+
42
+ def connection
43
+ params = {}
44
+ params[:key] = @api_key if @api_key
45
+ params[:format] = "json"
46
+
47
+ conn = Faraday.new(url: "#{API_URL}", params: params) do |builder|
48
+ builder.use Faraday::Request::UrlEncoded # convert request params as "www-form-urlencoded"
49
+ builder.use Faraday::Adapter::NetHttp # make http requests with Net::HTTP
50
+ end
51
+ end
52
+
53
+
54
+ end
55
+ end
56
+
57
+
data/yp.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/yp/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Allen Walker"]
6
+ gem.email = ["auswalk@gmail.com"]
7
+ gem.description = %q{Simple ruby wrapper for YP.com API}
8
+ gem.summary = %q{Simple ruby wrapper for YP.com 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 = "yp"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Yp::VERSION
17
+
18
+ gem.add_dependency('rails', '>= 3.0')
19
+ gem.add_dependency('faraday', ["< 0.8", ">= 0.6"])
20
+ gem.add_dependency('faraday_middleware', [">= 0.8"])
21
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1alpha
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Allen Walker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &14484780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *14484780
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &14483140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '0.8'
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0.6'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: *14483140
39
+ - !ruby/object:Gem::Dependency
40
+ name: faraday_middleware
41
+ requirement: &14481460 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *14481460
50
+ description: Simple ruby wrapper for YP.com API
51
+ email:
52
+ - auswalk@gmail.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - .gitignore
58
+ - Gemfile
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - lib/yp.rb
63
+ - lib/yp/version.rb
64
+ - yp.gemspec
65
+ homepage: ''
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>'
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.1
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Simple ruby wrapper for YP.com API
89
+ test_files: []