Created
June 11, 2017 11:08
-
-
Save amitpatelx/f1307afdbc7ae03d1f42106e41944e83 to your computer and use it in GitHub Desktop.
https://github.com/BoTreeConsultingTeam/magpress consumer examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CMS | |
class Base | |
HTTP_ERRORS = [Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError] | |
attr_reader :cms | |
def initialize(cms) | |
@cms = cms | |
end | |
def credentials | |
@credentials ||= cms.blog_connection_options | |
end | |
def handle_network_errors!(e, source) | |
#client.update_column(:connected, false) if client.connected? | |
error = e.message | |
Rails.logger.error "[ERROR] Unable to connect with WordPress(#{error}) due to network error in #{source}. Connection Options = #{cms.blog_connection_options.except(:password)}" | |
raise StandardError.new(I18n.t('errors.cms.network.connection_failed')) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CMS | |
class GetPost < CMS::Base | |
def call(post_id) | |
begin | |
Magpress::Post.new(credentials).find(post_id) | |
rescue *HTTP_ERRORS => e | |
handle_network_errors!(e, self) | |
rescue => e | |
Rails.logger.error "[ERROR] Problem while get post for #{credentials} (#{e.message})" | |
raise | |
end | |
end | |
private | |
def response(response) | |
Wordpress::ResponseProcessors::GetPost.new(response).generic_response | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment