Class: Doohly::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/doohly/client.rb

Overview

Main API client for Doohly

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token: nil, api_base_url: nil) ⇒ Client

Returns a new instance of Client.

Raises:



12
13
14
15
16
17
18
19
# File 'lib/doohly/client.rb', line 12

def initialize(api_token: nil, api_base_url: nil)
  @api_token = api_token || Doohly.configuration.api_token
  @api_base_url = api_base_url || Doohly.configuration.api_base_url

  raise ConfigurationError, "API token is required" if @api_token.nil? || @api_token.empty?

  @connection = build_connection
end

Instance Attribute Details

#api_base_urlObject (readonly)

Returns the value of attribute api_base_url.



10
11
12
# File 'lib/doohly/client.rb', line 10

def api_base_url
  @api_base_url
end

#api_tokenObject (readonly)

Returns the value of attribute api_token.



10
11
12
# File 'lib/doohly/client.rb', line 10

def api_token
  @api_token
end

Instance Method Details

#booking(id) ⇒ Hash

GET /v2/bookings/:id

Parameters:

  • id (String)

    Booking ID

Returns:

  • (Hash)

    Booking details



35
36
37
# File 'lib/doohly/client.rb', line 35

def booking(id)
  get("v2/bookings/#{id}")
end

#bookings(status: nil) ⇒ Hash

GET /v2/bookings

Parameters:

  • status (String, nil) (defaults to: nil)

    Filter by status (e.g., ‘booked’, ‘paused’, ‘completed’)

Returns:

  • (Hash)

    List of bookings



26
27
28
29
30
# File 'lib/doohly/client.rb', line 26

def bookings(status: nil)
  params = {}
  params[:status] = status if status
  get("v2/bookings", params)
end

#create_booking(name:, external_id: nil, plays_per_loop: nil, loops_per_play: nil, play_consecutively: nil, purchase_type: nil, campaign: nil, schedule: nil, assigned_creatives: nil, assigned_frames: nil, tags: nil, seedooh: nil, status: nil) ⇒ Hash

POST /v2/bookings - Create a new booking

Parameters:

  • name (String)

    Booking name

  • external_id (String, nil) (defaults to: nil)

    External reference ID

  • plays_per_loop (Integer, nil) (defaults to: nil)

    Number of plays per loop

  • loops_per_play (Integer, nil) (defaults to: nil)

    Number of loops per play

  • play_consecutively (Boolean, nil) (defaults to: nil)

    Whether to play consecutively

  • purchase_type (String, nil) (defaults to: nil)

    Purchase type (e.g., ‘Sold’, ‘Bonus’)

  • campaign (Hash, nil) (defaults to: nil)

    Campaign details

  • schedule (Hash, nil) (defaults to: nil)

    Schedule configuration

  • assigned_creatives (Array<Hash>, nil) (defaults to: nil)

    Array of creative assignments

  • assigned_frames (Array<Hash>, nil) (defaults to: nil)

    Array of frame assignments

  • tags (Array<String>, nil) (defaults to: nil)

    Tags for the booking

  • seedooh (Hash, nil) (defaults to: nil)

    SeeDooh configuration

  • status (String, nil) (defaults to: nil)

    Booking status

Returns:

  • (Hash)

    Created booking details



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/doohly/client.rb', line 54

def create_booking(name:, external_id: nil, plays_per_loop: nil, loops_per_play: nil,
                   play_consecutively: nil, purchase_type: nil, campaign: nil,
                   schedule: nil, assigned_creatives: nil, assigned_frames: nil,
                   tags: nil, seedooh: nil, status: nil)
  body = { name: name }
  body[:externalId] = external_id if external_id
  body[:playsPerLoop] = plays_per_loop if plays_per_loop
  body[:loopsPerPlay] = loops_per_play if loops_per_play
  body[:playConsecutively] = play_consecutively unless play_consecutively.nil?
  body[:purchaseType] = purchase_type if purchase_type
  body[:campaign] = campaign if campaign
  body[:schedule] = schedule if schedule
  body[:assignedCreatives] = assigned_creatives if assigned_creatives
  body[:assignedFrames] = assigned_frames if assigned_frames
  body[:tags] = tags if tags
  body[:seedooh] = seedooh if seedooh
  body[:status] = status if status

  post("v2/bookings", body)
end

#creative_upload_status(id) ⇒ Hash

GET /v1/library/creatives/upload/:id - Get creative upload status

Parameters:

  • id (String)

    Upload ID

Returns:

  • (Hash)

    Upload status



140
141
142
# File 'lib/doohly/client.rb', line 140

def creative_upload_status(id)
  get("v1/library/creatives/upload/#{id}")
end

#delete_booking(id) ⇒ Hash

DELETE /v2/bookings/:id - Delete an existing booking

Parameters:

  • id (String)

    Booking ID

Returns:

  • (Hash)

    Deletion result



116
117
118
# File 'lib/doohly/client.rb', line 116

def delete_booking(id)
  delete("v2/bookings/#{id}")
end

#device(id) ⇒ Hash

GET /v2/devices/:id

Parameters:

  • id (String)

    Device ID

Returns:

  • (Hash)

    Device details



131
132
133
# File 'lib/doohly/client.rb', line 131

def device(id)
  get("v2/devices/#{id}")
end

#devicesHash

GET /v1/devices

Returns:

  • (Hash)

    List of devices



124
125
126
# File 'lib/doohly/client.rb', line 124

def devices
  get("v1/devices")
end

#get_signed_upload_url(name:, mime_type:, file_size:, playback_scaling: nil, path: nil) ⇒ Hash

POST /v1/library/creatives/upload - Get signed upload URL

Parameters:

  • name (String)

    Creative name

  • mime_type (String)

    MIME type (e.g., ‘image/png’, ‘video/mp4’)

  • file_size (Integer)

    File size in bytes

  • playback_scaling (String, nil) (defaults to: nil)

    Playback scaling mode (e.g., ‘contain’, ‘cover’)

  • path (Array<String>, nil) (defaults to: nil)

    Folder path for organization

Returns:

  • (Hash)

    Upload information including signed URL



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/doohly/client.rb', line 151

def get_signed_upload_url(name:, mime_type:, file_size:, playback_scaling: nil, path: nil)
  body = {
    name: name,
    mimeType: mime_type,
    fileSize: file_size
  }
  body[:playbackScaling] = playback_scaling if playback_scaling
  body[:path] = path if path

  post("v1/library/creatives/upload", body)
end

#update_booking(id, name: nil, external_id: nil, plays_per_loop: nil, loops_per_play: nil, play_consecutively: nil, purchase_type: nil, campaign: nil, schedule: nil, assigned_creatives: nil, assigned_frames: nil, tags: nil, seedooh: nil, status: nil) ⇒ Hash

PATCH /v2/bookings/:id - Update an existing booking

Parameters:

  • id (String)

    Booking ID

  • name (String, nil) (defaults to: nil)

    Booking name

  • external_id (String, nil) (defaults to: nil)

    External reference ID

  • plays_per_loop (Integer, nil) (defaults to: nil)

    Number of plays per loop

  • loops_per_play (Integer, nil) (defaults to: nil)

    Number of loops per play

  • play_consecutively (Boolean, nil) (defaults to: nil)

    Whether to play consecutively

  • purchase_type (String, nil) (defaults to: nil)

    Purchase type

  • campaign (Hash, nil) (defaults to: nil)

    Campaign details

  • schedule (Hash, nil) (defaults to: nil)

    Schedule configuration

  • assigned_creatives (Array<Hash>, nil) (defaults to: nil)

    Array of creative assignments

  • assigned_frames (Array<Hash>, nil) (defaults to: nil)

    Array of frame assignments

  • tags (Array<String>, nil) (defaults to: nil)

    Tags for the booking

  • seedooh (Hash, nil) (defaults to: nil)

    SeeDooh configuration

  • status (String, nil) (defaults to: nil)

    Booking status

Returns:

  • (Hash)

    Updated booking details



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/doohly/client.rb', line 91

def update_booking(id, name: nil, external_id: nil, plays_per_loop: nil, loops_per_play: nil,
                   play_consecutively: nil, purchase_type: nil, campaign: nil,
                   schedule: nil, assigned_creatives: nil, assigned_frames: nil,
                   tags: nil, seedooh: nil, status: nil)
  body = {}
  body[:name] = name if name
  body[:externalId] = external_id unless external_id.nil?
  body[:playsPerLoop] = plays_per_loop if plays_per_loop
  body[:loopsPerPlay] = loops_per_play if loops_per_play
  body[:playConsecutively] = play_consecutively unless play_consecutively.nil?
  body[:purchaseType] = purchase_type if purchase_type
  body[:campaign] = campaign unless campaign.nil?
  body[:schedule] = schedule if schedule
  body[:assignedCreatives] = assigned_creatives if assigned_creatives
  body[:assignedFrames] = assigned_frames if assigned_frames
  body[:tags] = tags if tags
  body[:seedooh] = seedooh if seedooh
  body[:status] = status if status

  patch("v2/bookings/#{id}", body)
end