foursquare_document 0.0.3

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,18 @@
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
18
+ /nbproject/private/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foursquare_document.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Niels V
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,47 @@
1
+ # FoursquareDocument
2
+
3
+ Quick and easy foursquare venue_info cache in your mongo documents
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'foursquare_document'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install foursquare_document
18
+
19
+ ## Usage
20
+
21
+ include FoursquareDocument in your document and assign a field to contain the foursquare_id.
22
+ This will automatically embed a foursquare_cache document in your model. It is set using a after_save callback.
23
+
24
+ ```ruby
25
+ class Venue
26
+ include Mongoid::Document
27
+ include FoursquareDocument
28
+
29
+ foursquare_id :fs_id
30
+ end
31
+ ```
32
+
33
+ Create an initializer to set the foursquare credentials
34
+ ```ruby
35
+ FoursquareDocument::Config.configure do |c|
36
+ c.client_id = <your-id>
37
+ c.client_secret = <your-secret>
38
+ end
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/foursquare_document/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Niels V"]
6
+ gem.email = ["nvdk@arguslabs.be"]
7
+ gem.description = "Easily add foursquare venue information to any mongoid document."
8
+ gem.summary = "Embed foursquare venue information to any mongoid document."
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 = "foursquare_document"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = FoursquareDocument::VERSION
17
+ gem.add_runtime_dependency "mongoid", "~> 3.0.0"
18
+ gem.add_runtime_dependency 'foursquare2'
19
+ end
@@ -0,0 +1,49 @@
1
+ require "foursquare_document/version"
2
+ require "foursquare_document/models/foursquare_cache"
3
+ require "foursquare_document/config"
4
+ module FoursquareDocument
5
+ module ClassMethods
6
+ def foursquare_id(symbol,index=false)
7
+ field symbol, :type => Moped::BSON::ObjectId
8
+
9
+
10
+ if index
11
+ index({symbol => 1})
12
+ end
13
+
14
+ attr_accessible symbol, :foursquare_cache
15
+ accepts_nested_attributes_for :foursquare_cache
16
+
17
+ class_eval <<-RUBY, __FILE__, __LINE__+1
18
+ define_callbacks :add_foursquare_info
19
+
20
+ set_callback(:save,:after) do |doc|
21
+ if doc.#{symbol}_changed? &&
22
+ (doc.foursquare_cache.blank? || !doc.foursquare_cache.changed?)
23
+ doc.add_foursquare_info
24
+ end
25
+ end
26
+
27
+
28
+ def add_foursquare_info
29
+ run_callbacks :add_foursquare_info do
30
+ client = FoursquareDocument::Config::get_client
31
+ venue_info = client.venue(self.#{symbol})
32
+ self.foursquare_cache = FoursquareCache.new(venue_info)
33
+ self.foursquare_cache.save!
34
+ end
35
+ end
36
+ RUBY
37
+ end
38
+ end
39
+
40
+
41
+ def self.included(base)
42
+ # no need for activesupport::concern
43
+ base.send :extend, ClassMethods
44
+
45
+ base.class_eval do
46
+ embeds_one :foursquare_cache, :as => :fs_doc
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ require "foursquare2"
2
+ module FoursquareDocument
3
+ module Config
4
+ Configuration = Struct.new(:client_id,:client_secret)
5
+ FS_CONFIG = Configuration.new
6
+
7
+ def self.configure(&block)
8
+ yield FS_CONFIG
9
+ end
10
+
11
+ def self.get_client
12
+ @client = Foursquare2::Client.new(:client_id => FS_CONFIG.client_id, :client_secret => FS_CONFIG.client_secret)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class FoursquareCache
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps::Updated
4
+
5
+ field :name, :type => String
6
+ field :description, :type => String
7
+ field :categories, :type => Array
8
+ field :location, :type => Hash
9
+ field :id, :type => Moped::BSON::ObjectId
10
+
11
+ attr_accessible :name,:description,:categories,:location,:id
12
+
13
+ embedded_in :fs_doc,:polymorphic => true
14
+ end
@@ -0,0 +1,3 @@
1
+ module FoursquareDocument
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foursquare_document
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Niels V
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: &2164558940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2164558940
25
+ - !ruby/object:Gem::Dependency
26
+ name: foursquare2
27
+ requirement: &2164558520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2164558520
36
+ description: Easily add foursquare venue information to any mongoid document.
37
+ email:
38
+ - nvdk@arguslabs.be
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - foursquare_document.gemspec
49
+ - lib/foursquare_document.rb
50
+ - lib/foursquare_document/config.rb
51
+ - lib/foursquare_document/models/foursquare_cache.rb
52
+ - lib/foursquare_document/version.rb
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.12
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Embed foursquare venue information to any mongoid document.
77
+ test_files: []