posterous 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/posterous CHANGED
@@ -35,34 +35,48 @@ end
35
35
 
36
36
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
37
37
 
38
- %w{posterous irb}.each { |f| require f }
39
-
40
- rc = File.exists?(RC_PATH) ? File.open(RC_PATH, 'r') : File.open(RC_PATH, 'w')
41
- yml = YAML.load_file(RC_PATH)
38
+ %w{posterous irb fileutils}.each { |f| require f }
39
+
40
+
41
+ def setup
42
+ @yml = YAML.load_file(RC_PATH) rescue nil
43
+
44
+ if @yml.is_a?(Hash)
45
+ @cfg = @yml
46
+ else
47
+ @rc = File.open(RC_PATH, 'w')
48
+ @cfg = {}
49
+ puts "Email Address:"
50
+ @cfg['username'] = gets.chomp
51
+ begin
52
+ puts "Password:"
53
+ system('stty -echo')
54
+ @cfg['password'] = gets.chomp
55
+ rescue
56
+ ensure
57
+ system('stty echo')
58
+ end
59
+ puts "Api Token:"
60
+ @cfg['api_token'] = gets.chomp
61
+ @rc.puts @cfg.to_yaml
62
+ @rc.close
63
+ end
42
64
 
43
- if yml.is_a?(Hash)
44
- cfg = yml
45
- else
46
- cfg = {}
47
- puts "Email Address:"
48
- cfg['username'] = gets.chomp
65
+ Posterous.config = @cfg
66
+
49
67
  begin
50
- puts "Password:"
51
- system('stty -echo')
52
- cfg['password'] = gets.chomp
53
- rescue
54
- ensure
55
- system('stty echo')
68
+ Posterous::User.me
69
+ rescue Exception => e
70
+ FileUtils.rm(RC_PATH, :force => true)
71
+ puts "*"*100
72
+ puts "Invalid Login: #{e.inspect}"
73
+ puts "*"*100
74
+ setup
56
75
  end
57
- puts "Api Token:"
58
- cfg['api_token'] = gets.chomp
59
- rc.puts cfg.to_yaml
60
76
  end
61
77
 
62
- rc.puts cfg.to_yaml
63
- rc.close
78
+ setup
64
79
 
65
- Posterous.config = cfg
66
80
 
67
81
  include Posterous
68
82
 
@@ -70,6 +84,8 @@ def current_user
70
84
  @current_user ||= User.me
71
85
  end
72
86
 
87
+
88
+
73
89
  puts "*"*100
74
90
  puts "Hi #{current_user.nickname}, welcome to the Posterous API Console! For help type `newb`.\n"
75
91
  puts "*"*100
@@ -1,7 +1,8 @@
1
1
  module Posterous
2
2
  class AssociationProxy
3
3
  attr_reader :klass, :proxied
4
-
4
+
5
+ # poached from activerecord
5
6
  instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/ }
6
7
 
7
8
  def initialize proxied, klass, association_type, *args
@@ -9,7 +10,10 @@ module Posterous
9
10
  @proxied = proxied
10
11
  @association = nil
11
12
 
13
+ # set the parent id for the assoc class
12
14
  @association_klass.finder_opts[klass.resource_url_keys.last] = proxied.id
15
+ # grab any needed finder opts from the proxied instance
16
+ # and grab them from the parent resource
13
17
  @association_klass.finder_opts.merge!(@proxied.finder_opts)
14
18
 
15
19
  load_method = association_type == :many ? :all : :load
@@ -16,6 +16,18 @@ module Posterous
16
16
  AssociationProxy.new self, klass, :one, *args
17
17
  end
18
18
  end
19
+
20
+ def self.parsed_resource_url
21
+ resource_path.gsub(/:\w+/) {|sym| finder_opts[sym.sub(/:/,'').to_sym] }
22
+ end
23
+
24
+ def parsed_resource_url
25
+ self.class.parsed_resource_url
26
+ end
27
+
28
+ def self.resource_url_keys
29
+ resource_path.scan(/:(\w+)/).flatten.collect(&:to_sym)
30
+ end
19
31
 
20
32
  # hack for ruby 1.8.7
21
33
  def id
@@ -77,33 +89,26 @@ module Posterous
77
89
 
78
90
  new post(parsed_resource_url, param_scope => params, :media => media)
79
91
  end
92
+
93
+ # url used for the update & delete actions
94
+ def instance_url
95
+ "#{parsed_resource_url}/#{self.id}"
96
+ end
80
97
 
81
98
  def save
82
99
  return if hash_for_update.empty?
83
- @struct = self.class.post(parsed_resource_url + "/#{self.id}", { param_scope => hash_for_update, '_method' => 'put' } )
100
+ @struct = self.class.post(instance_url, { param_scope => hash_for_update, '_method' => 'put' } )
84
101
  changed_fields.clear
85
102
  end
86
103
 
87
104
  def destroy
88
- self.class.delete(parsed_resource_url + "/#{self.id}")
105
+ self.class.delete(instance_url)
89
106
  end
90
107
 
91
108
  def reload
92
109
  self.class.find(self.id)
93
110
  end
94
111
 
95
- def self.parsed_resource_url
96
- resource_path.gsub(/:\w+/) {|sym| finder_opts[sym.sub(/:/,'').to_sym] }
97
- end
98
-
99
- def parsed_resource_url
100
- self.class.parsed_resource_url
101
- end
102
-
103
- def self.resource_url_keys
104
- resource_path.scan(/:(\w+)/).flatten.collect(&:to_sym)
105
- end
106
-
107
112
  def initialize struct
108
113
  @struct = struct
109
114
  end
@@ -6,14 +6,9 @@ module Posterous
6
6
  'site_profile'
7
7
  end
8
8
 
9
- def save
10
- return if hash_for_update.empty?
11
- @struct = self.class.post(parsed_resource_url, { param_scope => hash_for_update, '_method' => 'put' } )
12
- changed_fields.clear
9
+ def instance_url
10
+ parsed_resource_url
13
11
  end
14
12
 
15
- def destroy
16
- self.class.delete(parsed_resource_url)
17
- end
18
13
  end
19
14
  end
@@ -1,3 +1,3 @@
1
1
  module Posterous
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Christopher Burnett @twoism
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-26 00:00:00 -07:00
17
+ date: 2011-05-09 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency