Class: Pixlee::API

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key, app_name) ⇒ API

Returns a new instance of API.



6
7
8
9
# File 'lib/pixlee.rb', line 6

def initialize(api_key, app_name)
    @api_key = api_key
    @app_name = app_name
end

Instance Method Details

#get_album_contents(album_id, options = {}) ⇒ Object

Method to get album contents. Options accepts: type, sort, page, per_page



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pixlee.rb', line 19

def get_album_contents(album_id, options = {})
    json = call_api("#{base_url}/albums/#{album_id}", options)

    response = {
        :photos => json["data"],
        :num_results => json["num_results"]
    }

    # These are only useful if using paginaiton (e.g. not requesting all)
    if options[:type] != 'all'
        response[:num_results_per_page] = json["num_results_per_page"]
        response[:total_photos] = json["num_results_per_page"]
        response[:page_previous_url] = json["page_next_url"]
        response[:page_previous_url] = json["page_next_url"]
    end

    return response
end

#get_album_photo(album_id, album_photo_id, options = {}) ⇒ Object

Method to get album contents. Options accepts: type, sort



39
40
41
42
43
44
45
46
47
# File 'lib/pixlee.rb', line 39

def get_album_photo(album_id, album_photo_id, options = {})
    json = call_api("#{base_url}/albums/#{album_id}/photos/#{album_photo_id}", options)

    reponse = json["data"]["photo"]
    reponse["updated_at"] = json["data"]["updated_at"]
    reponse["created_at"] = json["data"]["created_at"]

    return reponse
end

#get_albumsObject

Get all albums for a user



12
13
14
15
16
# File 'lib/pixlee.rb', line 12

def get_albums
    json = call_api("#{base_url}", {})

    return json["data"]
end

#get_users_albums(user_id, options = {}) ⇒ Object

Method to get users albums. Options accepts: type, sort



50
51
52
53
54
55
56
# File 'lib/pixlee.rb', line 50

def get_users_albums(user_id, options = {})
    json = call_api("http://api.pixlee.com/v1/#{user_id}", options)

    reponse = json["data"]["photo"]

    return reponse
end