139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/notehub/notehub.rb', line 139
def new_note(text, pass=false, options={})
options[:theme] ||= nil
options[:font] ||= nil
params = {}
params['note'] = text.strip
params['pid'] = @pid
params['signature'] = Digest::MD5.hexdigest(@pid + @psk + text.strip)
params['password'] = Digest::MD5.hexdigest(pass) if pass
params['version'] = API_VERSION
params['theme'] = options[:theme] unless options[:theme].nil?
params['text-font'] = options[:font] unless options[:font].nil?
params['header-font'] = options[:header_font] unless options[:header_font].nil?
res = post_api(params)
if res && res['status']['success']
note_data = read_note(res['noteID'])
note = {
'title' => note_data['title'][0..80],
'id' => res['noteID'],
'url' => res['longURL'],
'short' => res['shortURL'],
'stats' => note_data['statistics'],
'pass' => pass ? pass : "",
'file' => options[:file] ? options[:file] : ""
}
store_note(note)
return note
else
if res
raise "Failed: #{res['status']['comment']} "
else
raise "Failed to create note"
end
end
end
|