Snapcat

Build Status

A cat-tastic Ruby wrapper for the Snapchat private API. Meow. This gem is designed to give you a friendly Ruby-like interface for interacting with the Snapchat API.

Installation

Add this line to your application's Gemfile:

gem 'snapcat', '0.0.1'

And then execute:

$ bundle

Alternatively, install it via command line:

$ gem install snapcat

Usage

User Auth

# Initialize a client and login
snapcat = Snapcat::Client.new('your-username')
snapcat.('topsecretpassword')

# Initialize a new client, register, and login
snapcat = Snapcat::Client.new('your-new-username')
snapcat.register('topsecretpassword', '1990-01-20', '[email protected]')

# Logout
snapcat.logout

User Actions

# Block a user
snapcat.block('username-to-block')

# Clear feed
snapcat.clear_feed

# Fetch a user's updates
snapcat.fetch_updates

# Unblock a user
snapcat.unblock('username-to-unlock')

# Update user's email
snapcat.update_email('[email protected]')

# Update user's privacy setting
# Two choices:
#   Snapcat::User::Privacy::EVERYONE
#   Snapcat::User::Privacy::FRIENDS
snapcat.update_privacy(Snapcat::User::Privacy::EVERYONE)

# Pro tip:
#   Every call to the API responds with Snapcat::Response object with which
#   you can check a few important things
response = snapcat.block('username-to-block')
response.code # => 200
response.http_success # => true
response.data # => { logged: true, ... }

User Data

# Get the user
user = snapcat.user

# Examine all raw user data
user.data

# Examine snaps received
user.snaps_received

# Examine snaps sent
user.snaps_sent

# Examine friends
user.friends

Friends

# Add a new friend
snapcat.add_friend('mybestbuddy')

# Grab a friend
friend = user.friends.first

# Set a friend's display name
snapcat.set_display_name(friend.username, 'Nik Ro')

# Delete a friend :(
snapcat.delete_friend(friend.username)

# Learn more about your friend
friend.can_see_custom_stories
friend.display_name
friend.username

# What kind of friend are they anyway??
friend.type
friend.type.confirmed?
friend.type.unconfirmed?
friend.type.blocked?
friend.type.deleted?

Sending Snaps

# Send it to catsaregreat with 3 seconds duration
# `data` is a string which can be read directly from an mp4 or jpg
snapcat.send_media(data, 'catsaregreat')

# Or send it to multiple recipients and override default view_duration
snapcat.send_media(data, %w(catsaregreat ronnie99), view_duration: 4)

Received Snaps

# Grab a snap
snap = user.snaps_received.first

# Get the snap image or video data
media_response = snapcat.media_for(snap.id)
media = media_response.data[:media]

# Learn more about the media
media.image?
media.video?
media.file_extension
media.type_code

# Get the data from the media object
media.to_s

Snaps General

# Learn more about the snap
snap.broadcast
snap.broadcast_action_text
snap.broadcast_hide_timer
snap.broadcast_url
snap.screenshot_count
snap.media_id
snap.id
snap.media_type
snap.recipient
snap.sender
snap.status
snap.sent
snap.opened

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Add tests and make sure they pass
  6. Create new Pull Request

Credits

Copyright © 2013 Neal Kemp

Released under the MIT License, which can be found in the repository in LICENSE.txt.