Class: CS::Api
- Inherits:
-
Object
- Object
- CS::Api
- Defined in:
- lib/csapi.rb
Instance Attribute Summary collapse
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #friends(user = @uid) ⇒ Object
-
#initialize(username, password) ⇒ Api
constructor
A new instance of Api.
- #message(url) ⇒ Object
- #messages(*args) ⇒ Object
- #photos(user = @uid) ⇒ Object
- #profile(user = @uid) ⇒ Object
- #references(user = @uid) ⇒ Object
- #request(id) ⇒ Object
- #requests(limit = 10) ⇒ Object
- #search(options) ⇒ Object
- #userdata ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Api
Returns a new instance of Api.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/csapi.rb', line 45 def initialize(username, password) @username = username r = HTTP.post('/sessions', body:{username: username, password: password}.to_json) raise CS::APIError.new('Unsupported API version') if r.headers['X-CS-Error'] == 'clientVersionNotSupportedAnymore' raise CS::AuthError.new("Could not login") if r.code != 200 @cookies = [] @cookies=r.headers['Set-Cookie'].split(/;/).first #end data = JSON.parse r.body @uid = data['url'].gsub(/[^\d]/, '') @profile = data.keep_if {|k,v| ['realname', 'username', 'profile_image', 'gender', 'address'].include?(k)} @profile['uid'] = @uid HTTP.headers 'Cookie' => @cookies CS.instance = self end |
Instance Attribute Details
#uid ⇒ Object
Returns the value of attribute uid.
42 43 44 |
# File 'lib/csapi.rb', line 42 def uid @uid end |
Instance Method Details
#friends(user = @uid) ⇒ Object
118 119 120 121 122 |
# File 'lib/csapi.rb', line 118 def friends(user=@uid) url = "/users/#{user}/friends" r = HTTP.get(url) JSON.parse r.body end |
#message(url) ⇒ Object
93 94 95 96 |
# File 'lib/csapi.rb', line 93 def (url) r = HTTP.get(url) JSON.parse r.body end |
#messages(*args) ⇒ Object
88 89 90 |
# File 'lib/csapi.rb', line 88 def (*args) CS::Messages.getMessages(*args) end |
#photos(user = @uid) ⇒ Object
111 112 113 114 115 |
# File 'lib/csapi.rb', line 111 def photos(user=@uid) url = "/users/#{user}/photos" r = HTTP.get(url) JSON.parse r.body end |
#profile(user = @uid) ⇒ Object
104 105 106 107 108 |
# File 'lib/csapi.rb', line 104 def profile(user=@uid) url = "/users/#{user}/profile" r = HTTP.get(url) JSON.parse r.body end |
#references(user = @uid) ⇒ Object
125 126 127 128 129 |
# File 'lib/csapi.rb', line 125 def references(user=@uid) url = "/users/#{user}/references" r = HTTP.get(url) JSON.parse r.body end |
#request(id) ⇒ Object
81 82 83 84 85 |
# File 'lib/csapi.rb', line 81 def request(id) url = "/couchrequests/#{id}" r = HTTP.get(url) JSON.parse r.body end |
#requests(limit = 10) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/csapi.rb', line 65 def requests(limit=10) url = "/users/#{@uid}/couchrequests" q = { limit: limit } r = HTTP.get(url, query:q) requests = {} response = JSON.parse r.body response['object'].each do |req| key = req.gsub(/[^\d]/, '') requests[key] = self.request(key) end requests end |
#search(options) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/csapi.rb', line 132 def search() defaults = { location: nil, gender: nil, :'has-photo' => nil, :'member-type' => 'host' , vouched: nil, verified: nil, network: nil, :'min-age' => nil, :'max-age' => nil, :platform => 'android' } end |
#userdata ⇒ Object
99 100 101 |
# File 'lib/csapi.rb', line 99 def userdata @profile end |