Class: Mediumite::Client
- Inherits:
-
Object
- Object
- Mediumite::Client
- Defined in:
- lib/mediumite/client.rb
Instance Method Summary collapse
- #agent ⇒ Object
- #create_post(post) ⇒ Object
- #get_publications ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #request(method, path, data = {}) ⇒ Object
- #token ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 |
# File 'lib/mediumite/client.rb', line 5 def initialize( = {}) @options = end |
Instance Method Details
#agent ⇒ Object
19 20 21 22 23 24 |
# File 'lib/mediumite/client.rb', line 19 def agent @agent ||= Sawyer::Agent.new("https://api.medium.com/v1") do |http| http.headers[:content_type] = "application/json" http. "Bearer", token end end |
#create_post(post) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mediumite/client.rb', line 38 def create_post(post) if post.under_publication? request(:post, "publications/#{post.publication_id}/posts", post.to_json) else request(:post, "users/#{user.id}/posts", post.to_json) end end |
#get_publications ⇒ Object
34 35 36 |
# File 'lib/mediumite/client.rb', line 34 def get_publications request(:get, "users/#{user.id}/publications") end |
#inspect ⇒ Object
9 10 11 12 13 |
# File 'lib/mediumite/client.rb', line 9 def inspect inspected = super inspected = inspected.gsub! token, "#{'*'*token.length}" if token inspected end |
#request(method, path, data = {}) ⇒ Object
26 27 28 |
# File 'lib/mediumite/client.rb', line 26 def request(method, path, data = {}) agent.call(method, URI::Parser.new.escape(path.to_s), data).data.data end |
#token ⇒ Object
15 16 17 |
# File 'lib/mediumite/client.rb', line 15 def token @options[:token] end |
#user ⇒ Object
30 31 32 |
# File 'lib/mediumite/client.rb', line 30 def user @user ||= request(:get, "me") end |