Class: Snapcat::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/snapcat/client.rb', line 5

def initialize(username)
  @user = User.new
  @requestor = Requestor.new(username)
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/snapcat/client.rb', line 3

def user
  @user
end

Instance Method Details

#add_friend(username) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/snapcat/client.rb', line 53

def add_friend(username)
  @requestor.request_with_username(
    'friend',
    action: 'add',
    friend: username
  )
end

#auth_tokenObject



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

def auth_token
  @requestor.auth_token
end

#auth_token=(auth_token) ⇒ Object



14
15
16
# File 'lib/snapcat/client.rb', line 14

def auth_token=(auth_token)
  @requestor.auth_token = auth_token
end

#block(username) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/snapcat/client.rb', line 18

def block(username)
  @requestor.request_with_username(
    'friend',
    action: 'block',
    friend: username
  )
end

#clear_feedObject



26
27
28
# File 'lib/snapcat/client.rb', line 26

def clear_feed
  @requestor.request_with_username('clear')
end

#delete_friend(username) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/snapcat/client.rb', line 45

def delete_friend(username)
  @requestor.request_with_username(
    'friend',
    action: 'delete',
    friend: username
  )
end

#fetch_updates(update_timestamp = 0) ⇒ Object



30
31
32
33
34
35
# File 'lib/snapcat/client.rb', line 30

def fetch_updates(update_timestamp = 0)
  set_user_data_with(@requestor.request_with_username(
    'updates',
    update_timestamp: update_timestamp
  ))
end

#get_storiesObject



37
38
39
# File 'lib/snapcat/client.rb', line 37

def get_stories
  @requestor.request_with_username('stories')
end

#login(password) ⇒ Object



70
71
72
73
74
# File 'lib/snapcat/client.rb', line 70

def (password)
  set_user_data_with(
    @requestor.request_with_username('login', password: password)
  )
end

#logoutObject



76
77
78
# File 'lib/snapcat/client.rb', line 76

def logout
  @requestor.request_with_username('logout')
end

#media_for(snap_id) ⇒ Object



41
42
43
# File 'lib/snapcat/client.rb', line 41

def media_for(snap_id)
  @requestor.request_media(snap_id)
end

#register(password, birthday, email) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/snapcat/client.rb', line 80

def register(password, birthday, email)
  result = @requestor.request(
    'register',
    birthday: birthday,
    email: email,
    password: password
  )
  unless result.success?
    return result
  end

  result_two = @requestor.request_with_username(
    'registeru',
    email: email
  )

  set_user_data_with(result_two)
end

#screenshot(snap_id, view_duration = 1) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/snapcat/client.rb', line 99

def screenshot(snap_id, view_duration = 1)
  snap_data = {
    snap_id => {
      c: Snap::Status::SCREENSHOT,
      sv: view_duration,
      t: Timestamp.float
    }
  }
  events = [
    {
      eventName: 'SNAP_SCREENSHOT',
      params: { id: snap_id },
      ts: Timestamp.macro - view_duration
    }
  ]

  @requestor.request_with_username(
    'update_snaps',
    events: events.to_json,
    json: snap_data.to_json
  )
end

#send_media(data, recipients, options = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/snapcat/client.rb', line 122

def send_media(data, recipients, options = {})
  result = @requestor.request_upload(data, options[:type])

  unless result.success?
    return result
  end

  media_id = result.data[:media_id]

  @requestor.request_with_username(
    'send',
    media_id: media_id,
    recipient: prepare_recipients(recipients),
    time: options[:view_duration] || 3
  )
end

#send_story(data, options = {}) ⇒ Object



139
140
141
# File 'lib/snapcat/client.rb', line 139

def send_story(data, options = {})
  @requestor.request_upload_story(data, options[:time], options[:caption_text], options[:type])
end

#set_display_name(username, display_name) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/snapcat/client.rb', line 61

def set_display_name(username, display_name)
  @requestor.request_with_username(
    'friend',
    action: 'display',
    display: display_name,
    friend: username
  )
end

#unblock(username) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/snapcat/client.rb', line 143

def unblock(username)
  @requestor.request_with_username(
    'friend',
    action: 'unblock',
    friend: username
  )
end

#update_email(email) ⇒ Object



175
176
177
178
179
180
181
# File 'lib/snapcat/client.rb', line 175

def update_email(email)
  @requestor.request_with_username(
    'settings',
    action: 'updateEmail',
    email: email
  )
end

#update_privacy(code) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/snapcat/client.rb', line 183

def update_privacy(code)
  @requestor.request_with_username(
    'settings',
    action: 'updatePrivacy',
    privacySetting: code
  )
end

#view(snap_id, view_duration = 1) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/snapcat/client.rb', line 151

def view(snap_id, view_duration = 1)
  snap_data = {
    snap_id => { t: Timestamp.float, sv: view_duration }
  }
  events = [
    {
      eventName: 'SNAP_VIEW',
      params: { id: snap_id },
      ts: Timestamp.macro - view_duration
    },
    {
      eventName: 'SNAP_EXPIRED',
      params: { id: snap_id },
      ts: Timestamp.macro
    }
  ]

  @requestor.request_with_username(
    'update_snaps',
    events: events.to_json,
    json: snap_data.to_json
  )
end