lib/weary/resource.rb in weary-0.4.3 vs lib/weary/resource.rb in weary-0.5.0

- old
+ new

@@ -1,16 +1,17 @@ module Weary class Resource - attr_accessor :name, :domain, :with, :requires, :via, :format, :url, :authenticates, :follows, :headers + attr_accessor :name, :domain, :with, :requires, :via, :format, :url, :authenticates, :follows, :headers, :oauth, :access_token def initialize(name) self.name = name self.via = :get self.authenticates = false self.follows = true self.with = [] self.requires = [] + self.oauth = false end def name=(resource_name) resource_name = resource_name.to_s unless resource_name.is_a?(String) @name = resource_name.downcase.strip.gsub(/\s/,'_') @@ -80,18 +81,42 @@ pattern = pattern.gsub("<resource>", @name) pattern = pattern.gsub("<format>", @format.to_s) @url = pattern end - def authenticates? - if @authenticates + def oauth=(bool) + @authenticates = false if bool + @oauth = if bool true else false end end + def authenticates=(bool) + @oauth = false if bool + @authenticates = if bool + true + else + false + end + end + + def authenticates? + @authenticates + end + + def oauth? + @oauth + end + + def access_token=(token) + raise ArgumentError, "Token needs to be an OAuth::AccessToken object" unless token.is_a?(OAuth::AccessToken) + @oauth = true + @access_token = token + end + def follows_redirects? if @follows true else false @@ -105,10 +130,12 @@ :follows => follows_redirects?, :authenticates => authenticates?, :format => @format, :url => @url, :domain => @domain, - :headers => @headers}} + :headers => @headers, + :oauth => oauth?, + :access_token => @access_token}} end end end \ No newline at end of file