class GNUSocial::Client
This class manages calls to GNU Social API
Public Class Methods
new(node, user, passwd, options = {})
click to toggle source
Creates and configure a Client
for make calls to GNU Social API.
Arguments:
node: GNU Social instance user: Username passwd: Password Optional: ssl: Whether to use SSL, default false ssl_insecure: If is true, SSL cert will not be verified proxy_host: Proxy url used for the connection proxy_port: Proxy port used for the connection source: This is used for identify your app, default 'api'
# File lib/gsruby.rb, line 40 def initialize(node, user, passwd, options = {}) node = URI(node) if options[:proxy_host] && options[:proxy_port] proxy = [options[:proxy_host],options[:proxy_port]] end @node = Net::HTTP.new(node.hostname,node.port,*proxy) @user = user @passwd = passwd @source = options[:source] ? options[:source] : 'api' @node.use_ssl = true if options[:ssl] @node.verify_mode = OpenSSL::SSL::VERIFY_NONE if options[:ssl_insecure] end
Public Instance Methods
connect(path, params)
click to toggle source
Makes a request to the GNU Social instance.
Arguments:
path: Path to do the connection params: A hash containing additional parameters
# File lib/gsruby.rb, line 58 def connect(path, params) request = Net::HTTP::Post.new(path) request.basic_auth(@user,@passwd) request.set_form_data(params) res = @node.request(request) end
conversation(notice, options = {})
click to toggle source
Gets the full conversation of the given Notice
.
Arguments:
notice: NoticeID (integer) or Notice object options: Check get_timeline options
# File lib/gsruby.rb, line 115 def conversation(notice, options = {}) id = get_id(notice) get_timeline("/api/statusnet/conversation/#{id}.json",options) end
delete(notice)
click to toggle source
# File lib/gsruby.rb, line 188 def delete(notice) connect('',params) end
fav(notice)
click to toggle source
Marks the given notice as favorite.
Arguments:
notice: Notice to be marked as fav
# File lib/gsruby.rb, line 169 def fav(notice) id = get_id(notice) params = {:id => id} connect("/api/favorites/create/#{id}.json",params) end
get_id(notice)
click to toggle source
Return the ID of the given notice.
# File lib/gsruby.rb, line 144 def get_id(notice) if notice.is_a? Fixnum return notice elsif notice.is_a? Notice return notice.id else raise "Must be a integer or a Notice" end end
get_timeline(path, options = {})
click to toggle source
Makes a request to GNU Social instance and returns a Timeline
object.
Arguments:
path: Path to do the connection options: A hash containing additional parameters, that can be: since: Notice ID (integer). Request will return newer notices than the specified before: Notice ID (integer). Request will return older notices than the specified count: Integer. Number of notices that will be returned page: Number of page that will be returned, 1 page == 20 notices
# File lib/gsruby.rb, line 74 def get_timeline(path, options = {}) params = {} params[:since_id] = options[:since] if options[:since] params[:max_id] = options[:before] if options[:before] params[:count] = options[:count] if options[:count] params[:page] = options[:page] if options[:page] Timeline.from_json(connect(path,params).body) end
home_timeline(options = {})
click to toggle source
Gets the user’s Home Timeline
.
Arguments:
options: Check get_timeline options
# File lib/gsruby.rb, line 95 def home_timeline(options = {}) get_timeline('/api/statuses/home_timeline.json',options) end
mentions(options = {})
click to toggle source
Gets the user’s mentions.
Arguments:
options: Check get_timeline options
# File lib/gsruby.rb, line 103 def mentions(options = {}) get_timeline('/api/statuses/mentions.json',options) end
notice(id)
click to toggle source
Returns the notice with the given ID.
Arguments: id: ID of the notice to be returned
# File lib/gsruby.rb, line 124 def notice(id) res = @node.get("/api/statuses/show/#{id.to_s}.json") Notice.new(JSON.parse(res.body)) end
public_timeline(options = {})
click to toggle source
Gets the instance Public Timeline
.
Arguments:
options: Check get_timeline options
# File lib/gsruby.rb, line 87 def public_timeline(options = {}) get_timeline('/api/statuses/public_timeline.json',options) end
repeat(notice, options = {})
click to toggle source
Repeat the given notice.
Arguments:
notice: Notice to be repeated options: A hash containing additional parameters, that can be: source: Change the source of the status, default is source property
# File lib/gsruby.rb, line 181 def repeat(notice, options = {}) id = get_id(notice) params = {:id => id} params[:source] = options[:source] ? options[:source] : @source connect("/api/statuses/retweet/#{id}.json",params) end
reply(msg, notice, options = {})
click to toggle source
Publish a reply to the given Notice
.
Arguments:
msg: Message to be published notice: NoticeID (integer) or Notice object options: Check send_status options
# File lib/gsruby.rb, line 160 def reply(msg, notice, options = {}) options[:reply] = get_id(notice) send_status(msg,options) end
send_status(msg, options = {})
click to toggle source
Publish a new status.
Arguments:
msg: Message to be published options: A hash containing additional parameters, that can be: reply: Publish as reply of the given NoticeID (integer) or Notice object source: Change the source of the status, default is source property
# File lib/gsruby.rb, line 136 def send_status(msg, options = {}) params = {:status => msg} params[:in_reply_to_status_id] = options[:reply] if options[:reply] params[:source] = options[:source] ? options[:source] : @source connect('/api/statuses/update.json',params) end