Module: Buffer::Client::Update

Included in:
Buffer::Client
Defined in:
lib/buffer/update.rb

Instance Method Summary collapse

Instance Method Details

#check_id(id) ⇒ Object



69
70
71
72
# File 'lib/buffer/update.rb', line 69

def check_id(id)
  raise Buffer::Error::InvalidIdLength unless id.length == 24
  raise Buffer::Error::InvalidIdContent unless id[/^[a-f0-9]+$/i]
end

#create_update(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/buffer/update.rb', line 44

def create_update(options = {})
  options[:body].fetch(:text) do
    raise ArgumentError, "Must include text for update"
  end
  options[:body].fetch(:profile_ids) do
    raise ArgumentError, "Must include array of profile_ids"
  end
  post("/updates/create.json", options)
end

#destroy_update(update_id) ⇒ Object



65
66
67
# File 'lib/buffer/update.rb', line 65

def destroy_update(update_id)
  post("/updates/#{update_id}/destroy.json")
end

#interactions_by_update_id(id, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/buffer/update.rb', line 23

def interactions_by_update_id(id, options = {})
  check_id(id)
  response = get("/updates/#{id}/interactions.json", options)
  interactions = response['interactions'].map do |r|
    Buffer::Interaction.new(r)
  end
  Buffer::Interactions.new(
    { total: response['total'], interactions: interactions }
  )
end

#modify_update_text(update_id, options = {}) ⇒ Object



54
55
56
57
58
59
# File 'lib/buffer/update.rb', line 54

def modify_update_text(update_id, options = {})
  options[:body].fetch(:text) do
    raise ArgumentError, "Must include updated text"
  end
  post("/updates/#{update_id}/update.json", options)
end

#reorder_updates(profile_id, options = {}) ⇒ Object



34
35
36
37
# File 'lib/buffer/update.rb', line 34

def reorder_updates(profile_id, options = {})
  options.fetch(:order) { raise ArgumentError }
  post("/profiles/#{profile_id}/updates/reorder.json", body: options)
end

#share_update(update_id) ⇒ Object



61
62
63
# File 'lib/buffer/update.rb', line 61

def share_update(update_id)
  post("/updates/#{update_id}/share.json")
end

#shuffle_updates(profile_id, options = {}) ⇒ Object



39
40
41
42
# File 'lib/buffer/update.rb', line 39

def shuffle_updates(profile_id, options = {})
  post("/profiles/#{profile_id}/updates/shuffle.json",
                  body: options)
end

#update_by_id(id, options = {}) ⇒ Object



4
5
6
7
8
# File 'lib/buffer/update.rb', line 4

def update_by_id(id, options = {})
  check_id(id)
  response = get("/updates/#{id}.json")
  Buffer::Update.new(response)
end

#updates_by_profile_id(id, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/buffer/update.rb', line 10

def updates_by_profile_id(id, options = {})
  status = options.fetch(:status) do
    raise Buffer::Error::MissingStatus, "Include :pending or :sent in args"
  end
  options.delete(:status)
  response = get("/profiles/#{id}/updates/#{status.to_s}.json", options)
  updates = response['updates'].map { |r| Buffer::Update.new(r) }
  Buffer::Updates.new (
        { total: response['total'],
          updates: updates }
  )
end