Class: Thimbl::Base
- Inherits:
-
Object
- Object
- Thimbl::Base
- Defined in:
- lib/thimbl/base.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#plan_path ⇒ Object
readonly
Returns the value of attribute plan_path.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetch all the info and timelines of all the users you are following.
-
#follow(follow_nick, follow_address) ⇒ Object
Add a new user to follow.
-
#following ⇒ Object
Returns all the info about the users you are following.
-
#initialize(opts = {}) ⇒ Base
constructor
Initialize the thimbl client.
-
#load_data ⇒ Object
Charge into the ‘thimbl` object all the data into your `cache` file.
-
#messages ⇒ Object
Returns all the messages of you and all the users you are following in a chronologic order into a json format.
-
#post(text) ⇒ Object
Post a new message in your time-line.
-
#print ⇒ Object
Print every message of you and all the users you are following.
-
#push ⇒ Object
Send your actual ‘plan` file to your server.
-
#save_data ⇒ Object
Save all the data into the ‘thimbl` objecto into your `cache` file and `plan` file.
-
#setup(opts = {}) ⇒ Object
Setup a new configuration, the execution of this method will delete any thing in the ‘thimbl.plan_path` file and `thimbl.cache_path` file.
Constructor Details
#initialize(opts = {}) ⇒ Base
Initialize the thimbl client.
Use:
Thimbl.new(
:plan_path => <path to the plan file>,
:cache_path => <path to the cache file>
:user => <the user@domain>,
:password => <the user password>
)
44 45 46 47 48 49 50 51 52 |
# File 'lib/thimbl/base.rb', line 44 def initialize( opts = {} ) @plan_path = opts['plan_path'] @cache_path = opts['cache_path'] @user = opts['user'] @password = opts['password'] @data = nil @address = nil end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
32 33 34 |
# File 'lib/thimbl/base.rb', line 32 def address @address end |
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
32 33 34 |
# File 'lib/thimbl/base.rb', line 32 def cache_path @cache_path end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
32 33 34 |
# File 'lib/thimbl/base.rb', line 32 def data @data end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
32 33 34 |
# File 'lib/thimbl/base.rb', line 32 def password @password end |
#plan_path ⇒ Object (readonly)
Returns the value of attribute plan_path.
32 33 34 |
# File 'lib/thimbl/base.rb', line 32 def plan_path @plan_path end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
32 33 34 |
# File 'lib/thimbl/base.rb', line 32 def user @user end |
Class Method Details
.parse_time(time) ⇒ Object
219 220 221 |
# File 'lib/thimbl/base.rb', line 219 def self.parse_time( time ) Time.utc( time[0,4], time[4,2], time[6,2], time[8,2], time[10,2], time[12,2] ) end |
Instance Method Details
#fetch ⇒ Object
Fetch all the info and timelines of all the users you are following.
Use:
thimbl.fetch
137 138 139 140 141 142 143 144 145 |
# File 'lib/thimbl/base.rb', line 137 def fetch following.map { |f| f['address'] }.each do |followed_address| address_finger = Thimbl::Finger.run followed_address address_plan = address_finger.match(/Plan:\s*(.*)/m)[1].gsub("\\\n",'') data['plans'][followed_address] = JSON.load( address_plan ) end save_data end |
#follow(follow_nick, follow_address) ⇒ Object
Add a new user to follow
Use:
thimbl.follow 'nick', 'address'
To publish your following users you have to call:
thimbl.push
127 128 129 130 |
# File 'lib/thimbl/base.rb', line 127 def follow( follow_nick, follow_address ) data['plans'][address]['following'] << { 'nick' => follow_nick, 'address' => follow_address } save_data end |
#following ⇒ Object
Returns all the info about the users you are following.
Use:
thimbl.following
202 203 204 |
# File 'lib/thimbl/base.rb', line 202 def following data['plans'][address]['following'] end |
#load_data ⇒ Object
Charge into the ‘thimbl` object all the data into your `cache` file. Use:
thimbl.load_data
181 182 183 184 |
# File 'lib/thimbl/base.rb', line 181 def load_data @data = JSON.load( File.read cache_path ) @address = data['me'] end |
#messages ⇒ Object
Returns all the messages of you and all the users you are following in a chronologic order into a json format.
Use:
thimbl.
212 213 214 215 216 217 |
# File 'lib/thimbl/base.rb', line 212 def = data['plans'].values.map { |e| e['messages'] }.flatten = .sort { |a,b| a['time'] <=> b['time'] } return end |
#post(text) ⇒ Object
Post a new message in your time-line.
Use:
thimbl.post <message>
To publish your comment you have to call:
thimbl.push
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/thimbl/base.rb', line 108 def post( text ) = { 'address' => address, 'time' => Time.now.strftime('%Y%m%d%H%M%S'), 'text' => text } data['plans'][address]['messages'] << save_data end |
#print ⇒ Object
Print every message of you and all the users you are following.
Use:
thimbl.print
The method doesn’t print anything by it self. It just returns an string with all the comments.
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/thimbl/base.rb', line 154 def print result = "" .each do || result += Thimbl::Base.parse_time( ['time'] ).strftime( '%Y-%m-%d %H:%M:%S' ) result += " #{['address']}" result += " > #{['text']}" result += "\n" end return result end |
#push ⇒ Object
Send your actual ‘plan` file to your server
Use:
thimbl.push
171 172 173 174 175 |
# File 'lib/thimbl/base.rb', line 171 def push Net::SCP.start( user.split('@')[1], user.split('@')[0], :password => password ) do |scp| scp.upload!( plan_path, ".plan" ) end end |
#save_data ⇒ Object
Save all the data into the ‘thimbl` objecto into your `cache` file and `plan` file.
Use:
thimbl.save_data
192 193 194 195 |
# File 'lib/thimbl/base.rb', line 192 def save_data File.open( cache_path, 'w' ) { |f| f.write data.to_json } File.open( plan_path, 'w' ) { |f| f.write data['plans'][address].to_json } end |
#setup(opts = {}) ⇒ Object
Setup a new configuration, the execution of this method will delete any thing in the ‘thimbl.plan_path` file and `thimbl.cache_path` file.
Use:
thimbl.setup(
:bio => 'bio',
:website => 'website',
:mobile => 'mobile',
:email => 'email',
:address => 'address',
:name => 'name'
)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/thimbl/base.rb', line 67 def setup( opts = {} ) opts = { 'bio' => 'bio', 'website' => 'website', 'mobile' => 'mobile', 'email' => 'email', 'address' => 'address', 'name' => 'name' }.merge( opts ) @data = { 'me' => opts['address'], 'plans' => { opts['address'] => { 'name' => opts['name'], 'bio' => opts['bio'], 'properties' => { 'email' => opts['email'], 'mobile' => opts['mobile'], 'website' => opts['website'] }, 'following' => [], 'messages' => [], 'replies' => {} } } } @address = opts['address'] save_data end |