fluttrly 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Fluttrly
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/fluttrly-gem.rb CHANGED
@@ -35,8 +35,31 @@ module Fluttrly
35
35
  end
36
36
  end
37
37
 
38
- def post(list=nil, message=nil)
39
- puts "bouverdafs"
38
+ #Posting requires getting COOKIE om nom nom and a csrf token..
39
+ def post(list, message)
40
+ uri = URI.parse("http://fluttrly.com/#{list}")
41
+ http = Net::HTTP.new(uri.host, uri.port)
42
+ response = http.request(Net::HTTP::Get.new(uri.request_uri))
43
+
44
+ #get the csrf-token, really wanna use hpricot here but...
45
+ auth_token = $1 if response.body =~ /"authenticity_token".*value="(.+)"/ or nil
46
+ raise "No authenticity token found :(" if auth_token.nil?
47
+
48
+ #COOKIE COOKIE COOKIE COOKIE COOKIE COOKIE
49
+ cookie = response['set-cookie'].split('; ')[0]
50
+
51
+ #ok ok, now send that post data
52
+ uri = URI.parse('http://fluttrly.com/tasks.js')
53
+ request = Net::HTTP::Post.new(uri.request_uri)
54
+ params = {
55
+ 'authenticity_token' => auth_token,
56
+ 'task[name]' => "#{list}",
57
+ 'task[content]' => "#{message}"
58
+ }
59
+ request["Cookie"] = cookie
60
+ request.set_form_data(params)
61
+ response = http.request(request)
62
+
40
63
  end
41
64
 
42
65
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluttrly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brent Beer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-08 00:00:00 -06:00
18
+ date: 2011-02-10 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency