tuenti 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/tuenti.rb +11 -7
  3. data/tuenti.gemspec +4 -4
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,6 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'mechanize'
3
3
  require 'json'
4
+ DEBUG = false unless defined? DEBUG
4
5
 
5
6
  class Tuenti
6
7
  extend ActiveSupport::Memoizable
@@ -11,30 +12,33 @@ class Tuenti
11
12
  ALBUMS_URL = 'http://www.tuenti.com/?m=Search&func=get_user_custom_albums_for_data_source&ajax=1'
12
13
  EDIT_PHOTO_URL = 'http://www.tuenti.com/?m=Photoedit&func=process_edit_photo&ajax=1'
13
14
 
14
- CSRF_REGEXP = /csrf(")?[:=](")?([0-9a-zA-Z]+)\b/
15
- CSRF_REGEXP_INDEX = 3
15
+ CSFR_REGEXP = /csfr(")?[:=](")?([0-9a-zA-Z]+)\b/
16
+ CSFR_REGEXP_INDEX = 3
16
17
 
17
18
  def initialize(user, password, timezone = Time.now.utc_offset/3600)
18
19
  @agent = WWW::Mechanize.new
19
- @agent.post LOGIN_URL, :email => user, :input_password => password, :timezone => timezone
20
- @csrf = @agent.get(HOME_URL).body.match(CSRF_REGEXP)[CSRF_REGEXP_INDEX]
20
+ raise Exception if @agent.post(LOGIN_URL, :email => user, :input_password => password, :timezone => timezone).uri.to_s == LOGIN_URL
21
+ @csfr = @agent.get(HOME_URL).body.match(CSFR_REGEXP)[CSFR_REGEXP_INDEX]
21
22
  end
22
23
 
23
24
  def upload_photo(file, attributes = nil)
24
25
  qid = @agent.submit(upload_photo_form(file)).search('#request_data').text
26
+ puts "QID: #{qid}" if DEBUG
25
27
  id = nil
26
28
  # el formato del id es album_id-user_id-photo_id-user_id
27
29
  while id.nil? || id =~ /-0-/ do # hasta que no se procesa photo_id es 0
28
30
  sleep(0.5)
29
31
  id = @agent.post(UPLOAD_URL, :func => 'checkq', :qid => qid).search('#request_data').text
30
32
  end
33
+ puts "PHOTO ID: #{id}" if DEBUG
31
34
  if attributes
32
- options = {:csrf => @csrf, :collection_key => id, :photo_title => attributes[:title] || ''}
35
+ options = {:csfr => @csfr, :'item_ids[]' => id, :from_collection_key => id, :photo_title => attributes[:title] || ''}
33
36
  if attributes[:album]
34
37
  options[:'add_albums_collection_keys[]'] = album_id(attributes[:album])
35
- @new_albums_count = 0
38
+ #@new_albums_count = 0
39
+ puts options[:'add_albums_collection_keys[]'] if DEBUG
36
40
  end
37
- @agent.post EDIT_PHOTO_URL, options
41
+ @agent.post EDIT_PHOTO_URL + "&collection_key=#{id}", options
38
42
  end
39
43
  id
40
44
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tuenti}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sergio Cambra"]
12
- s.date = %q{2009-11-14}
12
+ s.date = %q{2010-06-01}
13
13
  s.description = %q{A non-official Ruby API for Tuenti}
14
14
  s.email = %q{sergio@enpijama.es}
15
15
  s.extra_rdoc_files = [
@@ -34,8 +34,8 @@ Gem::Specification.new do |s|
34
34
  s.rubygems_version = %q{1.3.5}
35
35
  s.summary = %q{A non-official Ruby API for Tuenti}
36
36
  s.test_files = [
37
- "test/test_tuenti.rb",
38
- "test/helper.rb"
37
+ "test/helper.rb",
38
+ "test/test_tuenti.rb"
39
39
  ]
40
40
 
41
41
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuenti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-14 00:00:00 +01:00
12
+ date: 2010-06-01 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -101,5 +101,5 @@ signing_key:
101
101
  specification_version: 3
102
102
  summary: A non-official Ruby API for Tuenti
103
103
  test_files:
104
- - test/test_tuenti.rb
105
104
  - test/helper.rb
105
+ - test/test_tuenti.rb