Class: ThreadsClientRuby::Core
- Inherits:
-
Object
- Object
- ThreadsClientRuby::Core
- Defined in:
- lib/threads_client_ruby.rb
Instance Method Summary collapse
-
#initialize(credentials = {}) ⇒ Core
constructor
A new instance of Core.
- #publish(options) ⇒ Object
- #user_info ⇒ Object
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() req_post_url = ThreadsClientRuby::POST_URL data = default_req_params() if [:image] req_post_url = ThreadsClientRuby::POST_WITH_IMAGE_URL data = req_params_with_image(data, [:image]) else data[:publish_mode] = 'text_post' end if [:url] || [:reply_id] data[:text_post_app_info] = {} data[:text_post_app_info][:link_attachment_url] = [:url] if [:url] data[:text_post_app_info][:reply_id] = [:reply_id] if [: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_info ⇒ Object
96 97 98 |
# File 'lib/threads_client_ruby.rb', line 96 def user_info { usertoken: user_token, userid: user_id } end |