Module: Buff::Client::Update
- Included in:
- Buff::Client
- Defined in:
- lib/buff/update.rb
Instance Method Summary collapse
- #check_id(id) ⇒ Object
-
#create_update(options = {}) ⇒ Object
TODO.
- #destroy_update(update_id, options = {}) ⇒ Object
- #interactions_by_update_id(id, options = {}) ⇒ Object
- #modify_update_text(update_id, options = {}) ⇒ Object
- #reorder_updates(profile_id, options = {}) ⇒ Object
- #share_update(update_id, options = {}) ⇒ Object
- #shuffle_updates(profile_id, options = {}) ⇒ Object
- #update_by_id(id, options = {}) ⇒ Object
- #updates_by_profile_id(id, options = {}) ⇒ Object
Instance Method Details
#check_id(id) ⇒ Object
78 79 80 81 |
# File 'lib/buff/update.rb', line 78 def check_id(id) raise Buff::InvalidIdLength unless id.length == 24 raise Buff::InvalidIdContent unless id[/^[a-f0-9]+$/i] end |
#create_update(options = {}) ⇒ Object
TODO
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/buff/update.rb', line 43 def create_update(={}) # POST Data # text=This%20is%20an%20example%20update& # profile_ids[]=4eb854340acb04e870000010& # profile_ids[]=4eb9276e0acb04bb81000067& # media[link]=http%3A%2F%2Fgoogle.com& # media[description]=The%20google%20homepage # options = { # text: "bodytext", # profile_ids: ["230958239058", "23059u2350923"], # media: { # link: "http://example.com", # description: "That example page" # } # } response = post("/updates/create.json", ) Hashie::Mash.new(JSON.parse response.body) end |
#destroy_update(update_id, options = {}) ⇒ Object
74 75 76 |
# File 'lib/buff/update.rb', line 74 def destroy_update(update_id, ={}) response = post("/updates/#{update_id}/destroy.json", ) end |
#interactions_by_update_id(id, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/buff/update.rb', line 22 def interactions_by_update_id(id, ={}) optional_params = [:page, :count, :event] response = get("/updates/#{id}/interactions.json", ) interactions = response['interactions'].map { |r| Buff::Interaction.new(r) } Buff::Interactions.new( { total: response['total'], interactions: interactions } ) end |
#modify_update_text(update_id, options = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/buff/update.rb', line 63 def modify_update_text(update_id, ={}) # text, (now, media, utc) .fetch(:text) { raise ArgumentError } response = post("/updates/#{update_id}/update.json", ) Hashie::Mash.new(JSON.parse response.body) end |
#reorder_updates(profile_id, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/buff/update.rb', line 31 def reorder_updates(profile_id, ={}) # order, optional: offset, utc order = .fetch(:order) { raise ArgumentError } response = post("/profiles/#{profile_id}/updates/reorder.json", ) end |
#share_update(update_id, options = {}) ⇒ Object
70 71 72 |
# File 'lib/buff/update.rb', line 70 def share_update(update_id, ={}) response = post("/updates/#{update_id}/share.json", ) end |
#shuffle_updates(profile_id, options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/buff/update.rb', line 37 def shuffle_updates(profile_id, ={}) # optional count, utc response = post("/profiles/#{profile_id}/updates/shuffle.json", ) end |
#update_by_id(id, options = {}) ⇒ Object
4 5 6 7 8 |
# File 'lib/buff/update.rb', line 4 def update_by_id(id, ={}) check_id(id) response = get("/updates/#{id}.json") Buff::Update.new(response) end |
#updates_by_profile_id(id, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/buff/update.rb', line 10 def updates_by_profile_id(id, ={}) optional_params = [ :page, :count, :since, :utc ] status = .fetch(:status) do raise Buff::MissingStatus, "Include :pending or :sent in args" end .delete(:status) response = get("/profiles/#{id}/updates/#{status.to_s}.json", ) updates = response['updates'].map { |r| Buff::Update.new(r) } Buff::Updates.new ( { total: response['total'], updates: updates } ) end |