fluttrly 0.0.3 → 0.0.4

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluttrly-gem (0.0.1)
4
+ fluttrly (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -12,5 +12,5 @@ PLATFORMS
12
12
  ruby
13
13
 
14
14
  DEPENDENCIES
15
- fluttrly-gem!
16
- json
15
+ fluttrly!
16
+ json (>= 1.5.1)
data/README.md CHANGED
@@ -13,15 +13,43 @@ command line utility myself. Sweet!
13
13
 
14
14
  ##Disclaimer
15
15
  If you somehow get hurt using this. You're retarded. That being said, I shipped this as soon as possible,
16
- so not all of the features are done yet.
16
+ so not all of the features are done yet. Also, by shipping as soon as possible I realize there's much
17
+ to be refactored.
17
18
 
18
19
 
19
20
  ##Usage
20
-
21
21
  ** List an item **
22
22
  #fluttrly <command> <list>
23
23
  $ fluttrly list bouverdafs
24
24
  Task => "Nothing to see here, move along" at => 02-08-2011 18:57 PM
25
-
25
+
26
+ ** Post an item **
27
+ #fluttrly <command> <list> <message>
28
+ $ fluttrly post bouverdafs "gem'd"
29
+ $ fluttrly list bouverdafs
30
+ Task => "gem'd" at => 02-10-2011 16:18 PM
31
+ Task => "Nothing to see here, move along" at => 02-08-2011 18:57 PM
32
+
33
+ ** Update a task **
34
+ #fluttrly <command> <list>
35
+ $ fluttrly update bouverdafs
36
+ 1: Task => "gem'd" at => 02-10-2011 16:18 PM (Completed? false)
37
+ 2: Task => "Nothing to see here, move along" at => 02-08-2011 18:57 PM (Completed? false)
38
+ Which item would you like to edit?
39
+ 1
40
+ $ fluttrly list bouverdafs
41
+ 1: Task => "gem'd" at => 02-10-2011 16:18 PM (Completed? true)
42
+ 2: Task => "Nothing to see here, move along" at => 02-08-2011 18:57 PM (Completed? false)
43
+
44
+
45
+
46
+
26
47
  ##Install
27
- $ gem install fluttrly
48
+ $ gem install fluttrly
49
+
50
+ ##TO DO
51
+ * Tom-doc this ish
52
+ * Removing items completely (1 or many)
53
+ * Adding to locked lists :\
54
+
55
+
data/fluttrly-gem.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Maintain and inspect your fluttrly lists.}
14
14
 
15
15
  s.rubyforge_project = "fluttrly-gem"
16
- s.add_development_dependency "json"
16
+ s.add_development_dependency "json", ">= 1.5.1"
17
17
 
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,3 +1,3 @@
1
1
  module Fluttrly
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/fluttrly-gem.rb CHANGED
@@ -17,30 +17,71 @@ module Fluttrly
17
17
  parse_arguments(command, list, message)
18
18
 
19
19
  end
20
-
20
+
21
21
  def parse_arguments(command, list, message)
22
22
  return list(list) if command == 'list'
23
23
  return post(list, message) if command == 'post'
24
+ return update(list) if command == 'update'
24
25
  end
25
26
 
27
+ def update(list)
28
+ response = form_response(list)[1]
29
+ page = list(list)
30
+ if page
31
+ puts 'Which item would you like to edit?'
32
+ num = STDIN.gets.chomp.to_i
33
+ id = page[num-1]["task"]["id"]
34
+ update_task(id,response)
35
+ end
36
+ end
26
37
 
27
38
  def list(list)
28
- uri = URI.parse("http://fluttrly.com/#{list}.json")
29
- http = Net::HTTP.new(uri.host, uri.port)
30
- response = http.request(Net::HTTP::Get.new(uri.request_uri))
31
-
32
- page = JSON.parse(response.body)
33
- page.each do |task|
34
- puts("Task => \"#{task["task"]["content"]}\" at => #{Time.parse(task["task"]["created_at"]).strftime("%m-%d-%Y %H:%M %p")} ")
39
+ response = form_response(list, true)[1]
40
+ if Net::HTTPSuccess === response
41
+ i = 1
42
+ page = JSON.parse(response.body)
43
+ page.each do |task|
44
+ puts("#{i}: Task => \"#{task["task"]["content"]}\" at => #{Time.parse(task["task"]["created_at"]).strftime("%m-%d-%Y %H:%M %p")} (Completed? #{task["task"]["completed"]})")
45
+ i = i+1
46
+ end
47
+ if page.empty?
48
+ puts "Oops, that list doesn't have any items yet!"
49
+ puts "Try: fluttrly post #{list} <message> first."
50
+ return false
51
+ end
52
+ page
53
+ else
54
+ response.error!
35
55
  end
36
56
  end
37
57
 
38
58
  #Posting requires getting COOKIE om nom nom and a csrf token..
39
59
  def post(list, message)
40
- uri = URI.parse("http://fluttrly.com/#{list}")
60
+ http, response = form_response(list)
61
+ if Net::HTTPSuccess === response
62
+ response = post_request(list, message, response,http)
63
+ else
64
+ response.error!
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def form_response(list, get=nil)
71
+
72
+ #refactors are welcome here =\
73
+ if get.nil?
74
+ uri = URI.parse("http://fluttrly.com/#{list}")
75
+ else
76
+ uri = URI.parse("http://fluttrly.com/#{list}.json")
77
+ end
78
+
41
79
  http = Net::HTTP.new(uri.host, uri.port)
42
80
  response = http.request(Net::HTTP::Get.new(uri.request_uri))
81
+ [http, response]
82
+ end
43
83
 
84
+ def post_request(list, message, response, http)
44
85
  #get the csrf-token, really wanna use hpricot here but...
45
86
  auth_token = $1 if response.body =~ /"authenticity_token".*value="(.+)"/ or nil
46
87
  raise "No authenticity token found :(" if auth_token.nil?
@@ -48,7 +89,7 @@ module Fluttrly
48
89
  #COOKIE COOKIE COOKIE COOKIE COOKIE COOKIE
49
90
  cookie = response['set-cookie'].split('; ')[0]
50
91
 
51
- #ok ok, now send that post data
92
+ #ok ok, NOW send that post data
52
93
  uri = URI.parse('http://fluttrly.com/tasks.js')
53
94
  request = Net::HTTP::Post.new(uri.request_uri)
54
95
  params = {
@@ -59,7 +100,25 @@ module Fluttrly
59
100
  request["Cookie"] = cookie
60
101
  request.set_form_data(params)
61
102
  response = http.request(request)
103
+ end
104
+
105
+ def update_task(id, response)
106
+ auth_token = $1 if response.body =~ /"csrf-token".*content="(.+)"/ or nil
107
+ raise "No authenticity token found :(" if auth_token.nil?
108
+
109
+ #COOKIE COOKIE COOKIE COOKIE COOKIE COOKIE
110
+ cookie = response['set-cookie'].split('; ')[0]
62
111
 
112
+ uri = URI.parse("http://fluttrly.com/tasks/#{id}")
113
+ http = Net::HTTP.new(uri.host, uri.port)
114
+ request = Net::HTTP::Put.new(uri.request_uri)
115
+ params = {
116
+ 'authenticity_token' => auth_token,
117
+ 'completed' => "true"
118
+ }
119
+ request["Cookie"] = cookie
120
+ request.set_form_data(params)
121
+ response = http.request(request)
63
122
  end
64
123
 
65
124
  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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
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-10 00:00:00 -06:00
18
+ date: 2011-02-12 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,10 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 1
30
30
  segments:
31
- - 0
32
- version: "0"
31
+ - 1
32
+ - 5
33
+ - 1
34
+ version: 1.5.1
33
35
  type: :development
34
36
  version_requirements: *id001
35
37
  description: Maintain and inspect your fluttrly lists.