Module: PyrxSynapse::Parsers

Defined in:
lib/pyrx_synapse/client.rb

Overview

Response parsers

Class Method Summary collapse

Class Method Details

.parse_batch_track(raw) ⇒ Object



47
48
49
50
# File 'lib/pyrx_synapse/client.rb', line 47

def parse_batch_track(raw)
  d = raw.is_a?(Hash) ? raw : {}
  BatchTrackResponse.new(accepted: d.fetch("accepted", 0).to_i, rejected: d.fetch("rejected", 0).to_i)
end

.parse_bulk_contact(raw) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/pyrx_synapse/client.rb', line 85

def parse_bulk_contact(raw)
  d = raw.is_a?(Hash) ? raw : {}
  BulkContactResponse.new(
    total: d.fetch("total", 0).to_i,
    created: d.fetch("created", 0).to_i,
    updated: d.fetch("updated", 0).to_i,
    skipped: d.fetch("skipped", 0).to_i,
    errors: d.fetch("errors", []) || []
  )
end

.parse_contact(raw) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pyrx_synapse/client.rb', line 52

def parse_contact(raw)
  d = raw.is_a?(Hash) ? raw : {}
  ContactResponse.new(
    id: d.fetch("id", "").to_s,
    external_id: d.fetch("external_id", "").to_s,
    email: d["email"],
    phone: d["phone"],
    first_name: d["first_name"],
    last_name: d["last_name"],
    timezone: d["timezone"],
    locale: d["locale"],
    properties: d["properties"] || {},
    tags: d["tags"] || [],
    created_at: d.fetch("created_at", "").to_s,
    updated_at: d.fetch("updated_at", "").to_s
  )
end

.parse_contact_list(raw) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pyrx_synapse/client.rb', line 70

def parse_contact_list(raw)
  d = raw.is_a?(Hash) ? raw : {}
  data_raw = d.fetch("data", [])
  contacts = data_raw.is_a?(Array) ? data_raw.map { |c| parse_contact(c) } : []
  m = d.fetch("meta", {})
  m = {} unless m.is_a?(Hash)
  meta = ContactListMeta.new(
    total: m.fetch("total", 0).to_i,
    page: m.fetch("page", 0).to_i,
    per_page: m.fetch("per_page", 0).to_i,
    total_pages: m.fetch("total_pages", 0).to_i
  )
  ContactListResponse.new(data: contacts, meta: meta)
end

.parse_send(raw) ⇒ Object



96
97
98
99
# File 'lib/pyrx_synapse/client.rb', line 96

def parse_send(raw)
  d = raw.is_a?(Hash) ? raw : {}
  SendResponse.new(email_log_id: d.fetch("email_log_id", "").to_s, status: d.fetch("status", "").to_s)
end

.parse_template(raw) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/pyrx_synapse/client.rb', line 101

def parse_template(raw)
  d = raw.is_a?(Hash) ? raw : {}
  TemplateResponse.new(
    id: d.fetch("id", "").to_s,
    name: d.fetch("name", "").to_s,
    slug: d.fetch("slug", "").to_s,
    subject: d.fetch("subject", "").to_s,
    body_html: d.fetch("body_html", "").to_s,
    sender_name: d["sender_name"],
    from_email: d["from_email"],
    reply_to: d["reply_to"],
    content_type: d["content_type"],
    created_at: d.fetch("created_at", "").to_s,
    updated_at: d.fetch("updated_at", "").to_s
  )
end

.parse_template_preview(raw) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/pyrx_synapse/client.rb', line 118

def parse_template_preview(raw)
  d = raw.is_a?(Hash) ? raw : {}
  TemplatePreviewResponse.new(
    subject: d["subject"],
    html: d["html"],
    suppressed: !!d.fetch("suppressed", false),
    suppressed_reason: d["suppressed_reason"]
  )
end

.parse_track(raw) ⇒ Object



42
43
44
45
# File 'lib/pyrx_synapse/client.rb', line 42

def parse_track(raw)
  d = raw.is_a?(Hash) ? raw : {}
  TrackResponse.new(event_id: d.fetch("event_id", "").to_s, status: d.fetch("status", "").to_s)
end