Class: TimetrapHarvest::NetworkClient
- Inherits:
-
Object
- Object
- TimetrapHarvest::NetworkClient
- Defined in:
- lib/timetrap_harvest/network_client.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
Instance Method Summary collapse
- #harvest_add_uri ⇒ Object
-
#initialize(config) ⇒ NetworkClient
constructor
A new instance of NetworkClient.
- #post(payload) ⇒ Object
Constructor Details
#initialize(config) ⇒ NetworkClient
Returns a new instance of NetworkClient.
8 9 10 11 12 |
# File 'lib/timetrap_harvest/network_client.rb', line 8 def initialize(config) @email = config.email @password = config.password @subdomain = config.subdomain end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
6 7 8 |
# File 'lib/timetrap_harvest/network_client.rb', line 6 def email @email end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
6 7 8 |
# File 'lib/timetrap_harvest/network_client.rb', line 6 def password @password end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
6 7 8 |
# File 'lib/timetrap_harvest/network_client.rb', line 6 def subdomain @subdomain end |
Instance Method Details
#harvest_add_uri ⇒ Object
26 27 28 |
# File 'lib/timetrap_harvest/network_client.rb', line 26 def harvest_add_uri URI("https://#{subdomain}.harvestapp.com/daily/add") end |
#post(payload) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/timetrap_harvest/network_client.rb', line 14 def post(payload) req = Net::HTTP::Post.new(harvest_add_uri.request_uri) req.basic_auth(email, password) req.body = payload.to_json req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' res = Net::HTTP.start(harvest_add_uri.hostname, harvest_add_uri.port, use_ssl: true) do |http| http.request(req) end end |