Class: Scrapers::RubyTapas::DpdCart
- Inherits:
-
Object
- Object
- Scrapers::RubyTapas::DpdCart
- Defined in:
- lib/scrapers/rubytapas/dpdcart.rb
Overview
DpdCart is a remote service gateway object (Gateway Pattern) that provides a connection to rubytapas.dpdcart.com where the RubyTapas episodes and download files are available, as well as the episode feed.
Constant Summary collapse
- DPDCART_HOST_FORMAT =
The subscription name will be filled in depending on which subscription I’m downloading from. This is a stock sprintf-type fill in where you pass in the subscription parameter with a value, thusly:
DPDCART_HOST % {subscription: "rubytapas"}
"%{subscription}.dpdcart.com"
- ENV_DPDCART_USER_FORMAT =
"%{subscription}_USER"
- ENV_DPDCART_PASSWORD_FORMAT =
"%{subscription}_USER"
- LOGIN_PATH =
'/subscriber/login'
- FEED_PATH =
'/feed'
- CONTENT_PATH =
"/subscriber/content"
Instance Attribute Summary collapse
-
#password ⇒ Object
Password for dpdcart acount.
-
#subscription ⇒ Object
Subscription at dbdcart.
-
#user ⇒ Object
User name for dpdcart account.
Instance Method Summary collapse
- #debug ⇒ Object
-
#download!(file) ⇒ Object
Download the file from dpdcart.
- #dpdcart_host ⇒ Object
- #dry_run ⇒ Object
- #env_dpdcart_password ⇒ Object
- #env_dpdcart_user ⇒ Object
-
#feed! ⇒ Object
Retreive the episode feed from dpdcart.
- #feed_url ⇒ Object
-
#initialize(user = nil, password = nil, subscription = 'rubytapas', options = {}) ⇒ DpdCart
constructor
Create a new instance of the DpdCart gateway.
- #login_url ⇒ Object
Constructor Details
#initialize(user = nil, password = nil, subscription = 'rubytapas', options = {}) ⇒ DpdCart
Create a new instance of the DpdCart gateway.
email address. account. (e.g. ‘rubytapas’ or ‘elixirsips’)
If the user and password are empty, the information will be obtained in the following order:
-
reading the environment variables ‘<subscriptiion>_USER` and
‘<subscription>_PASSWORD`
Note that <subscription> will be the subscription passed in
above.
-
reading the user’s ‘$HOME/.netrc` file and pulling the
credentials that match the host name for the subscription account.
If no credentials can be found, it will raise an error: ‘NoCredentialsError`.
74 75 76 77 78 79 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 74 def initialize(user=nil, password=nil, subscription='rubytapas', ={}) self. = self.subscription = subscription set_user_and_password(user, password) self.agent = Mechanize.new end |
Instance Attribute Details
#password ⇒ Object
Password for dpdcart acount
39 40 41 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 39 def password @password end |
#subscription ⇒ Object
Subscription at dbdcart
33 34 35 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 33 def subscription @subscription end |
#user ⇒ Object
User name for dpdcart account
36 37 38 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 36 def user @user end |
Instance Method Details
#debug ⇒ Object
44 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 44 def debug ; @debug ||= [:debug] ; end |
#download!(file) ⇒ Object
Download the file from dpdcart
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 87 def download!(file) login warn "DEBUG: downloading #{file}" if debug if dry_run warn "DEBUG: download skipped for dry run" if dry_run filename = file body = "no body" else page = agent.get(file) filename = page.filename body = page.body end [ filename, body ] end |
#dpdcart_host ⇒ Object
41 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 41 def dpdcart_host ; @dpdcart_host ||= DPDCART_HOST_FORMAT % {subscription: subscription} ; end |
#dry_run ⇒ Object
45 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 45 def dry_run ; @dry_run ||= [:dry_run] ; end |
#env_dpdcart_password ⇒ Object
43 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 43 def env_dpdcart_password ; @env_dpdcart_password ||= ENV_DPDCART_PASSWORD_FORMAT % {subscription: subscription} ; end |
#env_dpdcart_user ⇒ Object
42 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 42 def env_dpdcart_user ; @env_dpdcart_user ||= ENV_DPDCART_PASSWORD_FORMAT % {subscription: subscription} ; end |
#feed! ⇒ Object
Retreive the episode feed from dpdcart
82 83 84 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 82 def feed! http_fetch(feed_url) end |
#feed_url ⇒ Object
46 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 46 def feed_url ; @feed_url ||= URI("https://#{dpdcart_host}#{FEED_PATH}") ; end |
#login_url ⇒ Object
47 |
# File 'lib/scrapers/rubytapas/dpdcart.rb', line 47 def login_url ; @login_url ||= URI("https://#{dpdcart_host}#{LOGIN_PATH}") ; end |