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



49
50
51
52
53
54
55
# File 'lib/snapcat/client.rb', line 49

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



41
42
43
44
45
46
47
# File 'lib/snapcat/client.rb', line 41

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

#login(password) ⇒ Object



66
67
68
69
70
# File 'lib/snapcat/client.rb', line 66

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

#logoutObject



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

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

#media_for(snap_id) ⇒ Object



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

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

#register(password, birthday, email) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/snapcat/client.rb', line 76

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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/snapcat/client.rb', line 95

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



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/snapcat/client.rb', line 118

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

#set_display_name(username, display_name) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/snapcat/client.rb', line 57

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

#unblock(username) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/snapcat/client.rb', line 135

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

#update_email(email) ⇒ Object



167
168
169
170
171
172
173
# File 'lib/snapcat/client.rb', line 167

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

#update_privacy(code) ⇒ Object



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

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

#view(snap_id, view_duration = 1) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/snapcat/client.rb', line 143

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