Created
April 2, 2014 03:56
-
-
Save brunoocasali/9927712 to your computer and use it in GitHub Desktop.
Createing 1° Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SmileAPI | |
class Config | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
connection.rb | |
This file is part of SmileAPI | |
Copyright (C) 2014 - Bruno Casali | |
SmileAPI is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
SmileAPI is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with SmileAPI. If not, see <http://www.gnu.org/licenses/>. | |
=end | |
module SmileAPI | |
require 'mongo' | |
require 'uri' | |
require 'json' | |
class Connection | |
MONGOHQ_URL = 'mongodb://bruno:[email protected]:10087/smile_api' | |
def self.connect | |
return @db_connection if @db_connection | |
db = URI.parse(MONGOHQ_URL) | |
db_name = db.path.gsub(/^\//, '') | |
@db_connection = Mongo::Connection.new(db.host, db.port).db(db_name) | |
@db_connection.authenticate(db.user, db.password) unless (db.user.nil? || db.user.nil?) | |
@db_connection | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
message.rb | |
This file is part of SmileAPI | |
Copyright (C) 2014 - Bruno Casali | |
SmileAPI is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
SmileAPI is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with SmileAPI. If not, see <http://www.gnu.org/licenses/>. | |
=end | |
module SmileAPI | |
class Message | |
def getMessage | |
db = SmileAPI::Connection.connect | |
puts "Collections" | |
puts "===========" | |
collections = db.collection_names | |
puts collections | |
last_collection = collections[-1] | |
coll = db.collection(last_collection) | |
# just show 5 | |
docs = coll.find().limit(5) | |
puts "\n Documents in #{last_collection}" | |
puts " #{docs.count()} documents(s) found" | |
puts "==========================" | |
docs.each{ |doc| puts doc.to_json } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SmileAPI | |
class MessageEntity | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SmileAPI | |
require 'mongo' | |
attr_accessor :name, :language, :sex, :birthday | |
class Profile | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, this API makes you more happy :D, just in your begining but, I have much love to make it real. | |
The Smile API, going to a better World on the Web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Specification.new do |s| | |
s.name = 'smile_api' | |
s.version = '0.0.1' | |
s.date = '2014-03-22' | |
s.summary = "Smile API" | |
s.description = "This is a new form to programming to clients..." | |
s.authors = ["Bruno Casali"] | |
s.email = '[email protected]' | |
s.files = ["lib/message.rb", "lib/config.rb", "lib/message_entity.rb", "lib/profile.rb"] | |
s.homepage = 'http://www.cabuum.com.br/smile/' | |
s.license = 'MIT' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment