Class: Services::Wordpress

Inherits:
Service show all
Defined in:
app/models/services/wordpress.rb

Constant Summary collapse

MAX_CHARACTERS =
1000

Instance Attribute Summary collapse

Attributes inherited from Service

#access_level, #info

Instance Method Summary collapse

Methods inherited from Service

auth, first_from_omniauth, initialize_from_omniauth, options, #post_opts, #profile_photo_url, service_type, titles

Instance Attribute Details

#hostObject

Returns the value of attribute host


7
8
9
# File 'app/models/services/wordpress.rb', line 7

def host
  @host
end

#passwordObject

Returns the value of attribute password


7
8
9
# File 'app/models/services/wordpress.rb', line 7

def password
  @password
end

#pathObject

Returns the value of attribute path


7
8
9
# File 'app/models/services/wordpress.rb', line 7

def path
  @path
end

#usernameObject

Returns the value of attribute username


7
8
9
# File 'app/models/services/wordpress.rb', line 7

def username
  @username
end

Instance Method Details

#post(post, _url = "") ⇒ Object


15
16
17
18
19
20
21
22
23
24
# File 'app/models/services/wordpress.rb', line 15

def post(post, _url="")
  res = Faraday.new(url: "https://public-api.wordpress.com").post do |req|
    req.url "/rest/v1/sites/#{uid}/posts/new"
    req.body = post_body(post).to_json
    req.headers["Authorization"] = "Bearer #{access_token}"
    req.headers["Content-Type"] = "application/json"
  end

  JSON.parse res.env[:body]
end

#post_body(post) ⇒ Object


26
27
28
29
30
31
# File 'app/models/services/wordpress.rb', line 26

def post_body(post)
  {
    title:   post.message.title,
    content: post.message.markdownified(disable_hovercards: true)
  }
end

#providerObject

uid = blog_id


11
12
13
# File 'app/models/services/wordpress.rb', line 11

def provider
  "wordpress"
end