Module: Skittles::Client::Photo

Included in:
Skittles::Client
Defined in:
lib/skittles/client/photo.rb

Overview

Define methods related to photos.

Instance Method Summary collapse

Instance Method Details

#add_photo(file, options = {}) ⇒ Hashie::Mash

Allows users to add a new photo to a checkin, tip, or a venue in general.

Parameters:

  • file (String)

    Path to the file to upload.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • checkinId (String)

    The id of a checkin owned by the user.

  • tipId (String)

    The ID of a tip owned by the user.

  • venueId (String)

    The ID of a venue, provided only when adding a public photo of the venue in general, rather than a private checkin or tip photo using the parameters above.

  • broadcast (String)

    Whether to broadcast this photo to twitter, facebook or both.

  • Allows (Integer)

    for a public photo and viewable at the venue. Valid values are 1 and 0 (default).

  • ll (String)

    Latitude and longitude of the user's location.

  • llAcc (Decimal)

    Accuracy of the user's latitude and longitude, in meters.

  • alt (Decimal)

    Altitude of the user's location, in meters.

  • altAcc (Decimal)

    Vertical accuracy of the user's location, in meters.

Returns:

  • (Hashie::Mash)

    The photo that was just created.

See Also:

Requires Acting User:

  • Yes



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/skittles/client/photo.rb', line 36

def add_photo(file, options = {})
  options.merge!({
    :file => UploadIO.new(file, 'image/jpeg', 'image.jpg'),
    :oauth_token => access_token
  })
  uri = URI.parse("#{endpoint}/photos/add")
  File.open(file) do
    req = Net::HTTP::Post::Multipart.new(uri.path, options)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true if uri.scheme == 'https'
    resp = http.start do |net|
      net.request(req)
    end
    
    case resp.code.to_i
    when 200..299
      return Skittles::Utils.parse_json(resp.body).response.photo
    when 400..599
      Skittles::Utils.handle_foursquare_error(resp)
    end
  end
end

#photo(id) ⇒ Hashie::Mash

Get details of a photo.

Parameters:

  • id (String)

    The id of the photo to retrieve additional information for.

Returns:

  • (Hashie::Mash)

    A complete photo object.

See Also:

Requires Acting User:

  • Yes



15
16
17
# File 'lib/skittles/client/photo.rb', line 15

def photo(id)
  get("photos/#{id}").photo
end