evernote_oauth 0.1.2 → 0.1.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.
data/README.md CHANGED
@@ -121,6 +121,23 @@ Here are the additional methods for each types:
121
121
 
122
122
  Notes: Those methods call thrift API internally. The result will be cached in the object so that the second method call wouldn't thrift API again.
123
123
 
124
+ ### Image Adding ###
125
+ Additional method is defined in Note to be easily added an image:
126
+ ```ruby
127
+ note = Evernote::EDAM::Type::Note.new(
128
+ title: 'Note',
129
+ tagNames: ['Evernote API Sample']
130
+ )
131
+
132
+ filename = "enlogo.png"
133
+ image = File.open(filename, "rb") { |io| io.read }
134
+ hexdigest = note.add_resource(filename, image, 'image/png')
135
+ ```
136
+ You can use hexdigest within ENXML:
137
+ ```xml
138
+ <en-media type="image/png" hash="#{hexdigest}"/>
139
+ ```
140
+
124
141
  References
125
142
  ----------
126
143
  - Evernote Developers: http://dev.evernote.com/
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.version = EvernoteOAuth::VERSION
10
10
 
11
11
  s.authors = ["Evernote"]
12
- s.date = %q{2012-08-14}
12
+ s.date = Time.now.strftime('%Y-%m-%d')
13
13
  s.description = %q{evernote_oauth is a Ruby client for the Evernote API using OAuth and Thrift.}
14
14
  s.email = %q{api@evernote.com}
15
15
  s.files = ["LICENSE", "README.md", "evernote_oauth.gemspec"] + Dir.glob('{lib,spec}/**/*')
@@ -9,6 +9,26 @@ module Evernote
9
9
  def tags
10
10
  @tags ||= (tagGuids || []).map{|guid| note_store.getTag(guid)}
11
11
  end
12
+
13
+ def add_resource(filename, image, mime)
14
+ hash_func = Digest::MD5.new
15
+
16
+ data = Evernote::EDAM::Type::Data.new
17
+ data.size = image.size
18
+ data.bodyHash = hash_func.digest(image)
19
+ data.body = image
20
+
21
+ resource = Evernote::EDAM::Type::Resource.new
22
+ resource.mime = mime
23
+ resource.data = data
24
+ resource.attributes = Evernote::EDAM::Type::ResourceAttributes.new
25
+ resource.attributes.fileName = filename
26
+
27
+ self.resources = [] unless self.resources
28
+ self.resources << resource
29
+
30
+ hash_func.hexdigest(image)
31
+ end
12
32
  end
13
33
  end
14
34
  end
@@ -58,6 +58,7 @@ module EvernoteOAuth
58
58
 
59
59
  def thrift_client(client_class, url)
60
60
  transport = Thrift::HTTPClientTransport.new(url)
61
+ transport.add_headers('User-Agent' => "evernote_oauth v#{::EvernoteOAuth::VERSION}")
61
62
  protocol = Thrift::BinaryProtocol.new(transport)
62
63
  client_class.new(protocol)
63
64
  end
@@ -19,7 +19,13 @@ module EvernoteOAuth
19
19
 
20
20
  attr_name = underscore(self.class.name.split('::').last).to_sym
21
21
  attr_value = self
22
- [result].flatten.each{|r| r.define_singleton_method(attr_name){attr_value}}
22
+ [result].flatten.each{|r|
23
+ begin
24
+ r.define_singleton_method(attr_name){attr_value}
25
+ rescue TypeError # Fixnum/TrueClass/FalseClass/NilClass
26
+ next
27
+ end
28
+ }
23
29
  result
24
30
  end
25
31
 
@@ -1,3 +1,3 @@
1
1
  module EvernoteOAuth
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'evernote_oauth'
2
2
  require 'rspec'
3
3
 
4
- Dir.glob(File.join(File.join(File.dirname(__FILE__), "..", "lib"), "**")).each do |file|
4
+ Dir.glob(File.join(File.join(File.dirname(__FILE__), "..", "lib"), "**.rb")).each do |file|
5
5
  require file
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evernote_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-14 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth