Class: Services::Wordpress

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

Constant Summary collapse

MAX_CHARACTERS =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host


4
5
6
# File 'app/models/services/wordpress.rb', line 4

def host
  @host
end

#passwordObject

Returns the value of attribute password


4
5
6
# File 'app/models/services/wordpress.rb', line 4

def password
  @password
end

#pathObject

Returns the value of attribute path


4
5
6
# File 'app/models/services/wordpress.rb', line 4

def path
  @path
end

#usernameObject

Returns the value of attribute username


4
5
6
# File 'app/models/services/wordpress.rb', line 4

def username
  @username
end

Instance Method Details

#post(post, url = '') ⇒ Object


12
13
14
15
16
17
18
19
20
21
# File 'app/models/services/wordpress.rb', line 12

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

  JSON.parse res.env[:body]
end

#post_body(post) ⇒ Object


23
24
25
26
27
28
# File 'app/models/services/wordpress.rb', line 23

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

#providerObject

uid = blog_id


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

def provider
  "wordpress"
end