Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'faraday', '>= 0.8', '~> 0.14.0'
gem 'faraday', '~> 1.0'
gem 'json'

group :test do
Expand Down
164 changes: 164 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,170 @@ clevertap.upload(event)
clevertap.upload(events) # Works as well with [CleverTap::Event]
```

### Create a campaign
CleverTap documentation: https://developer.clevertap.com/docs/create-campaign-api

```ruby
client = CleverTap::Client.new(AUTH_ACCOUNT_ID, AUTH_PASSCODE)

## SMS
campaign = CleverTap::Campaign::Sms.new(
to: { 'Email' => ['john@doe.com'] },
tag_group: 'mytaggroup',
respect_frequency_caps: false,
content: { 'body' => 'Smsbody' }
)

client.create_campaign(campaign)
```


<details>
<summary>Web push example</summary>

```ruby
## Web push
campaign = CleverTap::Campaign::WebPush.new(
to: {
'FBID' => %w[102029292929388 114342342453463],
'Email' => ['john@doe.com', 'jane@doe.com'],
'Identity' => ['JohnDoe'],
'objectId' => [
'_asdnkansdjknaskdjnasjkndja',
'-adffajjdfoaiaefiohnefwprjf'
]
},
tag_group: 'my tag group',
campaign_id: 1_000_000_043,
respect_frequency_caps: false,
content: {
'title' => 'Hi!',
'body' => 'How are you doing today?',
'platform_specific' => { # Optional
'safari' => {
'deep_link' => 'https://apple.com',
'ttl' => 10
},
'chrome' => {
'image' => 'https://www.exampleImage.com',
'icon' => 'https://www.exampleIcon.com',
'deep_link' => ' https://google.co',
'ttl' => 10,
'require_interaction' => true,
'cta_title1' => 'title',
'cta_link1' => 'http://www.example2.com',
'cta_iconlink1' => 'https://www.exampleIcon2.com'
},
'firefox' => {
'icon' => 'https://www.exampleIcon.com',
'deep_link' => 'https://mozilla.org',
'ttl' => 10
}
}
}
)

client.create_campaign(campaign)
```
</details>


<details>
<summary>Push example</summary>

```ruby
## Push
campaign = CleverTap::Campaign::Push.new(
to: {
'FBID' => %w[
102029292929388
114342342453463
],
'GPID' => [
'1928288389299292'
],
'Email' => [
'john@doe.com',
'jane@doe.com'
],
'Identity' => [
'JohnDoe'
],
'objectId' => [
'_asdnkansdjknaskdjnasjkndja',
'-adffajjdfoaiaefiohnefwprjf'
]
},
tag_group: 'mytaggroup',
respect_frequency_caps: false,
content: {
'title' => 'Welcome',
'body' => 'Smsbody',
'platform_specific' => { # Optional
'ios' => {
'deep_link' => 'example.com',
'sound_file' => 'example.caf',
'category' => 'notification category',
'badge_count' => 1,
'key' => 'value_ios'
},
'android' => {
'background_image' => 'http://example.jpg',
'default_sound' => true,
'deep_link' => 'example.com',
'large_icon' => 'http://example.png',
'key' => 'value_android',
'wzrk_cid' => 'engagement'
}
}
}
)

client.create_campaign(campaign)
```
</details>


<details>
<summary>Email example</summary>

```ruby
## Email
campaign = CleverTap::Campaign::Email.new(
to: {
'FBID' => %w[
102029292929388
114342342453463
],
'GPID' => [
'1928288389299292'
],
'Email' => [
'john@doe.com',
'jane@doe.com'
],
'Identity' => [
'JohnDoe'
],
'objectId' => [
'_asdnkansdjknaskdjnasjkndja',
'-adffajjdfoaiaefiohnefwprjf'
]
},
tag_group: 'my tag group',
respect_frequency_caps: false,
content: {
'subject' => 'Welcome',
'body' => '<div>Your HTML content for the email</div>',
'sender_name' => 'CleverTap'
}
)

client.create_campaign(campaign)
```
</details>


### Send requests as *Dry Run*

Passing parameter `dry_run: true` to upload methods you can test the data submitted for a validation errors.
Expand Down
2 changes: 1 addition & 1 deletion clever_tap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
'public gem pushes.'
end

spec.add_dependency 'faraday', '>= 0.8', '<= 0.14.0'
spec.add_dependency 'faraday', '~> 1.0'
spec.add_dependency 'json'

spec.add_development_dependency 'bundler', '~> 1.14'
Expand Down
11 changes: 11 additions & 0 deletions lib/clever_tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

require 'clever_tap/config'
require 'clever_tap/client'
require 'clever_tap/campaign'
require 'clever_tap/campaign/sms'
require 'clever_tap/campaign/web_push'
require 'clever_tap/campaign/push'
require 'clever_tap/campaign/email'
require 'clever_tap/entity'
require 'clever_tap/event'
require 'clever_tap/profile'
require 'clever_tap/uploader'
require 'clever_tap/campaign_creator'
require 'clever_tap/response'
require 'clever_tap/successful_response'
require 'clever_tap/failed_response'
Expand Down Expand Up @@ -66,6 +72,11 @@ def upload_profile(profile, **options)
upload_profiles([profile], options)
end

def create_campaign(campaign)
response = CampaignCreator.new(campaign).call(client)
normalize_response(response, records: [campaign])
end

private

def normalize_response(response, records:)
Expand Down
Loading