moomerman-twitter_oauth 0.1.15 → 0.1.16

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.
@@ -20,8 +20,22 @@ module TwitterOAuth
20
20
  JSON.parse(oauth_response.body)
21
21
  end
22
22
 
23
+ # Updates profile background image. Takes a File object and optional tile argument.
24
+ # Returns extended user info object.
25
+ def update_profile_background_image(image, tile = false)
26
+ body, headers = http_multipart_data({:image => image, :tile => tile})
27
+ oauth_response = access_token.post('/account/update_profile_background_image.json', body, headers)
28
+ end
29
+
30
+ # Updates profile avatar image. Takes a File object which should be an image.
31
+ # Returns extended user info object.
32
+ def update_profile_image(image)
33
+ body, headers = http_multipart_data({:image => image})
34
+ oauth_response = access_token.post('/account/update_profile_image.json', body, headers)
35
+ end
36
+
23
37
  # colors hash must contain at least one or more of the following keys :profile_background_color, :profile_text_color, :profile_link_color, :profile_sidebar_fill_color, :profile_sidebar_border_color
24
- # returns extended user info object
38
+ # returns extended user info object.
25
39
  def update_profile_colors(colors)
26
40
  oauth_response = access_token.post('/account/update_profile_colors.json', colors)
27
41
  JSON.parse(oauth_response.body)
@@ -7,6 +7,7 @@ require 'twitter_oauth/blocks'
7
7
  require 'twitter_oauth/friendships'
8
8
  require 'twitter_oauth/user'
9
9
  require 'twitter_oauth/favorites'
10
+ require 'twitter_oauth/utils'
10
11
 
11
12
  module TwitterOAuth
12
13
  class Client
@@ -0,0 +1,34 @@
1
+ module TwitterOAuth
2
+ class Client
3
+ CRLF = "\r\n"
4
+
5
+ private
6
+ # Properly encodes images in form/multipart specification for upload via OAuth.
7
+ def http_multipart_data(params)
8
+ body = ""
9
+ headers = {}
10
+
11
+ boundary = Time.now.to_i.to_s(16)
12
+
13
+ headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
14
+ params.each do |key,value|
15
+ esc_key = OAuth::Helper.escape(key.to_s)
16
+ body << "--#{boundary}#{CRLF}"
17
+
18
+ if value.respond_to?(:read)
19
+ mime_type = MIME::Types.type_for(value.path)[0] || MIME::Types["application/octet-stream"][0]
20
+ body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}"
21
+ body << "Content-Type: #{mime_type.simplified}#{CRLF*2}"
22
+ body << value.read
23
+ else
24
+ body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}"
25
+ end
26
+ end
27
+
28
+ body << "--#{boundary}--#{CRLF*2}"
29
+ headers["Content-Length"] = body.size.to_s
30
+
31
+ return [ body, headers ]
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moomerman-twitter_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Taylor
@@ -54,6 +54,7 @@ files:
54
54
  - lib/twitter_oauth/notifications.rb
55
55
  - lib/twitter_oauth/user.rb
56
56
  - lib/twitter_oauth/favorites.rb
57
+ - lib/twitter_oauth/utils.rb
57
58
  has_rdoc: false
58
59
  homepage: http://github.com/moomerman/twitter_oauth
59
60
  post_install_message: