Class: Tumblr::Post
- Inherits:
-
Object
- Object
- Tumblr::Post
- Defined in:
- lib/tumblr/post.rb
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
alias of find(:all).
-
.count(options = {}) ⇒ Object
count the posts.
-
.create(*args) ⇒ Object
create a new post.
-
.destroy(*args) ⇒ Object
destroy a post.
-
.find(*args) ⇒ Object
works just like ActiveRecord’s find.
-
.find_every(options) ⇒ Object
find all posts.
-
.find_from_id(id) ⇒ Object
find a post by id.
-
.find_initial(options) ⇒ Object
find the first post.
-
.find_last(options) ⇒ Object
find the last post.
-
.first(options = {}) ⇒ Object
alias of find(:first).
-
.last(options = {}) ⇒ Object
alias of find(:last).
-
.process_options(*args) ⇒ Object
extracts options from the arguments, converts a user object to :email and :password params and fixes the :post_id/‘post-id’ issue.
-
.update(*args) ⇒ Object
update a post.
Class Method Details
.all(options = {}) ⇒ Object
alias of find(:all)
74 75 76 |
# File 'lib/tumblr/post.rb', line 74 def self.all( = {}) self.find(:all, ) end |
.count(options = {}) ⇒ Object
count the posts
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tumblr/post.rb', line 17 def self.count( = {}) #puts balh = {:num => 1}.merge(options).to_yaml response = Tumblr::Request.read({:num => 1}.merge()) if(.empty?) #puts response['tumblr']['posts'].to_yaml #puts "*****" end response['tumblr']['posts']['total'].to_i end |
.create(*args) ⇒ Object
create a new post
89 90 91 92 |
# File 'lib/tumblr/post.rb', line 89 def self.create(*args) = (*args) Tumblr::Request.write() end |
.destroy(*args) ⇒ Object
destroy a post
101 102 103 104 |
# File 'lib/tumblr/post.rb', line 101 def self.destroy(*args) = (*args) Tumblr::Request.delete() end |
.find(*args) ⇒ Object
works just like ActiveRecord’s find. (:all, :first, :last or id)
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/tumblr/post.rb', line 5 def self.find(*args) = args.last.is_a?(Hash) ? args.pop : {} case args.first when :all then return self.find_every() when :first then return self.find_initial() when :last then return self.find_last() else return self.find_from_id(args.first) end end |
.find_every(options) ⇒ Object
find all posts
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tumblr/post.rb', line 46 def self.find_every() amount = (Tumblr::Post.count().to_f / 50).ceil = {:num => 50}.merge() responses = [] amount.times do |count| responses << Tumblr::Request.read(.merge({:start => (count.to_i * 50)})) #puts options.merge({:start => (count.to_i * 50)}).to_yaml end response = {'tumblr' => {'posts' => {'post' => []}}} responses.each do |r| r['tumblr']['posts']['post'].each { | p | response['tumblr']['posts']['post'] << p } end #puts response['tumblr']['posts']['post'].length.to_yaml return [response['tumblr']['posts']['post']] unless(response['tumblr']['posts']['post'].is_a?(Array)) response['tumblr']['posts']['post'] end |
.find_from_id(id) ⇒ Object
find a post by id
68 69 70 71 |
# File 'lib/tumblr/post.rb', line 68 def self.find_from_id(id) response = Tumblr::Request.read(:id => id) response['tumblr']['posts']['post'] end |
.find_initial(options) ⇒ Object
find the first post
30 31 32 33 34 35 36 37 |
# File 'lib/tumblr/post.rb', line 30 def self.find_initial() total = self.count = {:start => (total - 1), :num => 1} if(.empty?) response = Tumblr::Request.read() return response['tumblr']['posts']['post'].first unless( == {:start => (total - 1), :num => 1}) response['tumblr']['posts']['post'] end |
.find_last(options) ⇒ Object
find the last post
40 41 42 43 |
# File 'lib/tumblr/post.rb', line 40 def self.find_last() response = Tumblr::Request.read({:num => 1}.merge()) response['tumblr']['posts']['post'] end |
.first(options = {}) ⇒ Object
alias of find(:first)
79 80 81 |
# File 'lib/tumblr/post.rb', line 79 def self.first( = {}) self.find(:first, ) end |
.last(options = {}) ⇒ Object
alias of find(:last)
84 85 86 |
# File 'lib/tumblr/post.rb', line 84 def self.last( = {}) self.find(:last, ) end |
.process_options(*args) ⇒ Object
extracts options from the arguments, converts a user object to :email and :password params and fixes the :post_id/‘post-id’ issue.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/tumblr/post.rb', line 107 def self.(*args) = args.last.is_a?(Hash) ? args.pop : {} if((user = args.first).is_a?(Tumblr::User)) = .merge( :email => user.email, :password => user.password ) end if([:post_id]) ['post-id'] = [:post_id] [:post_id] = nil end return end |