Class: Ully::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ully.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.



18
19
20
# File 'lib/ully.rb', line 18

def initialize(access_token)
    self.class.default_params :access_token => access_token
end

Class Method Details

.pretty_response(response, format) ⇒ Object

Pretty responses in terminal



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ully.rb', line 23

def self.pretty_response(response, format)
    json = JSON.parse(response.body)
    json_response = json["response"]
    if format == "json"
        JSON.pretty_generate(json_response)
    elsif format == "yaml"
        json_response.to_yaml
    else
        json_response
    end
end

Instance Method Details

#account(format = false) ⇒ Object

Show profile info



54
55
56
57
# File 'lib/ully.rb', line 54

def (format=false)
    response = self.class.get("/account")
    self.class.pretty_response(response, format)
end

#collections(format = false) ⇒ Object

Show collections



66
67
68
69
# File 'lib/ully.rb', line 66

def collections(format=false)
    response = self.class.get("/collections", :query => {:fields => "name,slug,urls,public"})
    self.class.pretty_response(response, format)
end

#collections_by_username(username, format = false) ⇒ Object

Show collections by username



72
73
74
75
# File 'lib/ully.rb', line 72

def collections_by_username(username, format=false)
    response = self.class.get("/collections/of/"+username, :query => {:fields => "name,slug,urls,public"})
    self.class.pretty_response(response, format)
end

#create_collections(name, slug, public_collection = true, format = false) ⇒ Object

Create collections



78
79
80
81
# File 'lib/ully.rb', line 78

def create_collections(name, slug, public_collection=true, format=false)
    response = self.class.post("/collections", :body => {:name => name, :slug => slug, :public => public_collection})
    self.class.pretty_response(response, format)
end

#create_urls(collection_slug, url, title = "", description = "", format = false) ⇒ Object

Create urls



96
97
98
99
# File 'lib/ully.rb', line 96

def create_urls(collection_slug, url, title="", description="", format=false)
    response = self.class.post("/collections/"+collection_slug+"/urls", :body => {:title => title, :url => url, :description => description})
    self.class.pretty_response(response, format)
end

#delete_collections(collection_slug, format = false) ⇒ Object

Delete collections



90
91
92
93
# File 'lib/ully.rb', line 90

def delete_collections(collection_slug, format=false)
    response = self.class.delete("/collections/"+collection_slug)
    self.class.pretty_response(response, format)
end

#delete_urls(collection_slug, url_id, format = false) ⇒ Object

Delete urls



108
109
110
111
# File 'lib/ully.rb', line 108

def delete_urls(collection_slug, url_id, format=false)
    response = self.class.delete("/collections/"+collection_slug+"/urls/"+url_id)
    self.class.pretty_response(response, format)
end

#stats(format = false) ⇒ Object

Stats of Ully



36
37
38
39
# File 'lib/ully.rb', line 36

def stats(format=false)
    response = self.class.get("/stats")
    self.class.pretty_response(response, format)
end

#stats_by_username(username, format = false) ⇒ Object

Stats of Ully



42
43
44
45
# File 'lib/ully.rb', line 42

def stats_by_username(username, format=false)
    response = self.class.get("/stats/"+username)
    self.class.pretty_response(response, format)
end

#status(format = false) ⇒ Object

Status of Ully API



48
49
50
51
# File 'lib/ully.rb', line 48

def status(format=false)
    response = self.class.get("/status")
    self.class.pretty_response(response, format)
end

#update_account(current_password, name = "", email = "", username = "", password = "", format = false) ⇒ Object

Update profile info



60
61
62
63
# File 'lib/ully.rb', line 60

def (current_password, name="", email="", username="", password="", format=false)
    response = self.class.put("/account", :body => {:name => name, :email => email, :username => username, :currentpassword => current_password, :password => password})
    self.class.pretty_response(response, format)
end

#update_collections(collection_slug, name = "", slug = "", public_collection = true, format = false) ⇒ Object

Update collections



84
85
86
87
# File 'lib/ully.rb', line 84

def update_collections(collection_slug, name="", slug="", public_collection=true, format=false)
    response = self.class.put("/collections/"+collection_slug, :body => {:name => name, :slug => slug, :public => public_collection})
    self.class.pretty_response(response, format)
end

#update_urls(collection_slug, url_id, url, title = "", description = "", format = false) ⇒ Object

Update urls



102
103
104
105
# File 'lib/ully.rb', line 102

def update_urls(collection_slug, url_id, url, title="", description="", format=false)
    response = self.class.put("/collections/"+collection_slug+"/urls/"+url_id, :body => {:title => title, :url => url, :description => description})
    self.class.pretty_response(response, format)
end