Class: Cuenote::Api::Connection
- Inherits:
-
Object
- Object
- Cuenote::Api::Connection
- Defined in:
- lib/cuenote/api/connection.rb
Instance Method Summary collapse
- #body ⇒ Object
- #build ⇒ Object
- #builder ⇒ Object
- #config ⇒ Object
-
#initialize(*commands) ⇒ Connection
constructor
A new instance of Connection.
- #password ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
- #send ⇒ Object
- #uri ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(*commands) ⇒ Connection
Returns a new instance of Connection.
9 10 11 |
# File 'lib/cuenote/api/connection.rb', line 9 def initialize *commands @commands = commands end |
Instance Method Details
#body ⇒ Object
35 36 37 38 39 40 |
# File 'lib/cuenote/api/connection.rb', line 35 def body { CCC: "愛", xml: build } end |
#build ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cuenote/api/connection.rb', line 42 def build builder.forcast do |forcast| @commands.map.with_index do |command, id| forcast << command.build(id) end end.tap{|xml| puts xml } end |
#builder ⇒ Object
31 32 33 |
# File 'lib/cuenote/api/connection.rb', line 31 def builder @builder ||= ::Builder::XmlMarkup.new end |
#config ⇒ Object
62 63 64 |
# File 'lib/cuenote/api/connection.rb', line 62 def config Cuenote::Api.config end |
#password ⇒ Object
58 59 60 |
# File 'lib/cuenote/api/connection.rb', line 58 def password config.password end |
#request ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/cuenote/api/connection.rb', line 23 def request req = Net::HTTP::Post.new(uri) req.basic_auth username, password req.content_type = 'form-data' req.body = body.map{|k,v| "#{k}=#{v}" }.join("&") req end |
#response ⇒ Object
19 20 21 |
# File 'lib/cuenote/api/connection.rb', line 19 def response @response ||= Result.new(send.body) end |
#send ⇒ Object
13 14 15 16 17 |
# File 'lib/cuenote/api/connection.rb', line 13 def send Net::HTTP.start uri.hostname, uri.port, use_ssl: (uri.scheme == 'https') do |http| http.request request end.tap {|res| puts res.body } end |
#uri ⇒ Object
50 51 52 |
# File 'lib/cuenote/api/connection.rb', line 50 def uri @uri ||= URI(config.endpoint) end |
#username ⇒ Object
54 55 56 |
# File 'lib/cuenote/api/connection.rb', line 54 def username config.username end |