Class: Appcast::Client
- Inherits:
-
Object
- Object
- Appcast::Client
- Defined in:
- lib/appcast/client.rb
Defined Under Namespace
Classes: Message
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #create(name, content) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
Symbolized option hash.
- #list(name, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Symbolized option hash
37 38 39 40 |
# File 'lib/appcast/client.rb', line 37 def initialize( = {}) raise ClientError, "No :host option given." unless .key?(:host) @connection = Net::HTTP.new([:host], [:port]) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
34 35 36 |
# File 'lib/appcast/client.rb', line 34 def connection @connection end |
Instance Method Details
#create(name, content) ⇒ Object
42 43 44 45 |
# File 'lib/appcast/client.rb', line 42 def create(name, content) response = connection.post(URI.escape("/queue/#{name}"), content) Message.new(connection, :id => response["Location"].scan(/\d+$/).first, :name => name, :content => content) end |
#list(name, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/appcast/client.rb', line 47 def list(name, = {}) params = .inject([]) do |memo, (key, value)| memo << "#{key}=#{value}" if [:limit, :lock_for].include?(key) memo end params = params.empty? ? '' : "?#{params * "&"}" response = connection.get(URI.escape("/queue/#{name}#{params}")) = Hash.from_xml(response.body)['messages'] return [] if .nil? || !.key?('message') = ['message'] if .respond_to?(:collect!) .collect! do |hash| Message.new(connection, hash) end else [Message.new(connection, )] end end |