Class: SurgeAPI::Resources::Campaigns

Inherits:
Object
  • Object
show all
Defined in:
lib/surge_api/resources/campaigns.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Campaigns

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Campaigns.

Parameters:



127
128
129
# File 'lib/surge_api/resources/campaigns.rb', line 127

def initialize(client:)
  @client = client
end

Instance Method Details

#create(account_id, campaign_params:, request_options: {}) ⇒ SurgeAPI::Models::Campaign

Some parameter documentations has been truncated, see Models::CampaignCreateParams for more details.

Creates a campaign to register account to send text messages.

Parameters:

  • account_id (String)

    The account for which the campaign should be created.

  • campaign_params (SurgeAPI::CampaignParams)

    Parameters for creating a new campaign. Either provide full campaign details or

  • request_options (SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/surge_api/resources/campaigns.rb', line 22

def create(, params)
  parsed, options = SurgeAPI::CampaignCreateParams.dump_request(params)
  case parsed
  in {campaign_params: Hash => union, **rest}
    parsed = {**rest, **union}
  else
  end
  @client.request(
    method: :post,
    path: ["accounts/%1$s/campaigns", ],
    body: parsed,
    model: SurgeAPI::Campaign,
    options: options
  )
end

#list(account_id, after: nil, before: nil, request_options: {}) ⇒ SurgeAPI::Internal::Cursor<SurgeAPI::Models::Campaign>

Some parameter documentations has been truncated, see Models::CampaignListParams for more details.

List all campaigns for an account with cursor-based pagination.

Parameters:

  • account_id (String)

    The account ID to list campaigns for.

  • after (String)

    Cursor for forward pagination. Use the next_cursor from a previous response.

  • before (String)

    Cursor for backward pagination. Use the previous_cursor from a previous response

  • request_options (SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/surge_api/resources/campaigns.rb', line 111

def list(, params = {})
  parsed, options = SurgeAPI::CampaignListParams.dump_request(params)
  query = SurgeAPI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["accounts/%1$s/campaigns", ],
    query: query,
    page: SurgeAPI::Internal::Cursor,
    model: SurgeAPI::Campaign,
    options: options
  )
end

#retrieve(id, request_options: {}) ⇒ SurgeAPI::Models::Campaign

Retrieves a Campaign object.

Parameters:

  • id (String)

    The ID of the campaign to retrieve.

  • request_options (SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



49
50
51
52
53
54
55
56
# File 'lib/surge_api/resources/campaigns.rb', line 49

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["campaigns/%1$s", id],
    model: SurgeAPI::Campaign,
    options: params[:request_options]
  )
end

#update(id, campaign_params:, request_options: {}) ⇒ SurgeAPI::Models::Campaign

Some parameter documentations has been truncated, see Models::CampaignUpdateParams for more details.

Updates a campaign that has not yet been approved. This can be used to fix issues flagged during review and resubmit the campaign. Returns an error if the campaign is currently in review, has already been approved, or has been deactivated.

Parameters:

  • id (String)

    The ID of the campaign to update.

  • campaign_params (SurgeAPI::CampaignParams)

    Parameters for creating a new campaign. Either provide full campaign details or

  • request_options (SurgeAPI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/surge_api/resources/campaigns.rb', line 77

def update(id, params)
  parsed, options = SurgeAPI::CampaignUpdateParams.dump_request(params)
  case parsed
  in {campaign_params: Hash => union, **rest}
    parsed = {**rest, **union}
  else
  end
  @client.request(
    method: :patch,
    path: ["campaigns/%1$s", id],
    body: parsed,
    model: SurgeAPI::Campaign,
    options: options
  )
end