Class: ThreadsClientRuby::Core

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

Instance Method Summary collapse

Constructor Details

#initialize(credentials = {}) ⇒ Core

Returns a new instance of Core.



64
65
66
67
68
69
70
71
72
73
# File 'lib/threads_client_ruby.rb', line 64

def initialize(credentials = {})
  if credentials.is_a?(Hash)
    @username = credentials[:username]
    @password = credentials[:password]
    @user_token = credentials[:usertoken]
    @user_id = credentials[:userid]
  else
    raise "Invalid credentials"
  end
end

Instance Method Details

#publish(options) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/threads_client_ruby.rb', line 75

def publish(options)
  req_post_url = ThreadsClientRuby::POST_URL
  data = default_req_params(options)
  if options[:image]
    req_post_url = ThreadsClientRuby::POST_WITH_IMAGE_URL
    data = req_params_with_image(data, options[:image])
  else
    data[:publish_mode] = 'text_post'
  end
  if options[:url] || options[:reply_id]
    data[:text_post_app_info] = {}
    data[:text_post_app_info][:link_attachment_url] = options[:url] if options[:url]
    data[:text_post_app_info][:reply_id] = options[:reply_id] if options[:reply_id]
  end
  url = URI.parse(req_post_url)
  headers = get_app_headers
  payload = "signed_body=SIGNATURE.#{URI.encode_www_form_component(JSON.generate(data))}"
  response = HTTParty.post(url, headers: headers, body: payload)
  p response_handler(response)
end

#user_infoObject



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

def 
  { usertoken: user_token, userid: user_id }
end