placed 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.rbc
3
+ pkg/*
4
+ .bundle
5
+ .config
6
+ Gemfile.lock
7
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in placed.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 txarli
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,65 @@
1
+ # Placed
2
+
3
+ Placed is a gem created to raw interact with google api places.
4
+
5
+ It is in a completely embryonic state, and (for now) is not recommended for use in production projects.
6
+
7
+ But ... you could use it at your own risk!
8
+
9
+ ## Installation
10
+
11
+ Add this two lines to your application's Gemfile:
12
+
13
+ gem 'httparty'
14
+ gem 'placed'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Then...
21
+
22
+ $ rails g placed:config
23
+
24
+ It creates Placed gem configuration file at config/placed.yml, feed it with your base config + a valid Google Places API KEY
25
+
26
+
27
+ ## Usage
28
+
29
+ Instantiate a place
30
+
31
+ @somewhat = Placed::Location.new(address: "Calle Mallorca 401 08013 Barcelona", name: "Sagrada Familia")
32
+
33
+ Play a bit.. (all results are in json, directly from the Places API)
34
+
35
+ @somewhat.location
36
+
37
+ Returns a json object, which is to be used to send to the API
38
+
39
+ @somewhat.put
40
+
41
+ Perform a post, sending the object and loading it into the API
42
+
43
+ @somewhat.remove
44
+
45
+ Perform a post, deleting object from the API
46
+
47
+ @somewhat.reference
48
+
49
+ Returns the API unique identifier
50
+
51
+ @somewhat.get_coords
52
+
53
+ Just query the api, and transforms the address in coordinates
54
+
55
+ @somewhat.place
56
+
57
+ Returns information about whether or not it is loaded in the api
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/named_base'
5
+
6
+ module Placed
7
+ module Generators
8
+ class ConfigGenerator < Rails::Generators::Base
9
+ desc 'Creates Placed gem configuration file at config/placed.yml'
10
+
11
+ def self.source_root
12
+ @placed_source_root ||= File.expand_path("../templates", __FILE__)
13
+ end
14
+
15
+ def create_config_file
16
+ template 'placed.yml', File.join('config', 'placed.yml')
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ general: &general
2
+
3
+ default_types: 'store'
4
+ default_name: 'Unnamed'
5
+ default_accuracy: 50
6
+ default_language: 'en'
7
+
8
+ development:
9
+ <<: *general
10
+ api_key: "feed-me-with-a-valid-api-key"
11
+
12
+ test:
13
+ <<: *general
14
+ api_key: ""
15
+
16
+ production:
17
+ <<: *general
18
+ api_key: ""
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'generators/config_generator'
4
+
5
+ %w(location version).each do |file|
6
+ require File.join(File.dirname(__FILE__), 'placed', file)
7
+ end
@@ -0,0 +1,60 @@
1
+ module Placed
2
+ class Location
3
+
4
+ attr_reader :api_key, :address, :lat, :lng, :types, :name, :accuracy, :language, :public, :ref
5
+
6
+ def initialize(options = {})
7
+ raise "No address no fun!" if options[:address].nil?
8
+ @api_key = Placed.config['api_key']
9
+ @address = options[:address]
10
+ @types = options[:types] ||= Placed.config['default_types']
11
+ @name = options[:name] ||= Placed.config['default_name']
12
+ @accuracy = options[:accuracy] ||= Placed.config['default_accuracy']
13
+ @language = options[:language] ||= Placed.config['default_language']
14
+ @lat = get_coords[:lat] rescue "Unknown"
15
+ @lng = get_coords[:lng] rescue "Unknown"
16
+ @ref = placed['results'][0]['reference'] rescue nil
17
+ end
18
+
19
+ def get_coords
20
+ data = HTTParty.get("http://maps.google.com/maps/api/geocode/json?address=#{ERB::Util.u(self.address)}&sensor=false")
21
+ return { lat: data['results'][0]['geometry']['location']['lat'], lng: data['results'][0]['geometry']['location']['lng'] } if data['results']
22
+ end
23
+
24
+ def put
25
+ url = "https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key=#{self.api_key}"
26
+ @result = HTTParty.post(url.to_str, :body => location, :headers => { 'Content-Type' => 'application/json' } )
27
+ end
28
+
29
+ def remove
30
+ url = "https://maps.googleapis.com/maps/api/place/delete/json?sensor=false&key=#{self.api_key}"
31
+ @result = HTTParty.post(url.to_str, :body => reference, :headers => { 'Content-Type' => 'application/json' } )
32
+ @ref = nil if @result['status'] == "OK"
33
+ return @result
34
+ end
35
+
36
+ def placed
37
+ data = HTTParty.get("https://maps.googleapis.com/maps/api/place/search/json?location=#{self.lat},#{self.lng}&radius=3&name=#{ERB::Util.u(self.name)}&sensor=false&key=#{self.api_key}")
38
+ return data
39
+ end
40
+
41
+ def location
42
+ { location: { lat: self.lat, lng: self.lng },
43
+ accuracy: self.accuracy,
44
+ name: self.name,
45
+ types: [ self.types ],
46
+ language: self.language
47
+ }.to_json
48
+ end
49
+
50
+ def reference
51
+ { reference: self.ref }.to_json
52
+ end
53
+
54
+ end
55
+
56
+ def self.config
57
+ @config ||= YAML.load_file("#{Rails.root}/config/placed.yml")[Rails.env] rescue nil
58
+ end
59
+
60
+ end
@@ -0,0 +1,3 @@
1
+ module Placed
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/placed/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "placed"
6
+ s.version = Placed::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Txarli San"]
9
+ s.email = ["gabriel@pixind.com"]
10
+ s.homepage = "https://github.com/pixind/placed"
11
+ s.summary = %q{Google Places API.}
12
+ s.description = %q{This gem provides very basic functionalities to interact with Google Places API.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency 'httparty'
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: placed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Txarli San
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70340521190180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70340521190180
25
+ description: This gem provides very basic functionalities to interact with Google
26
+ Places API.
27
+ email:
28
+ - gabriel@pixind.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - lib/generators/config_generator.rb
39
+ - lib/generators/templates/placed.yml
40
+ - lib/placed.rb
41
+ - lib/placed/location.rb
42
+ - lib/placed/version.rb
43
+ - placed.gemspec
44
+ homepage: https://github.com/pixind/placed
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.10
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Google Places API.
68
+ test_files: []