Class: Everhour2toggl::Toggl::Post
- Inherits:
-
Object
- Object
- Everhour2toggl::Toggl::Post
- Defined in:
- lib/everhour2toggl/toggl/post.rb
Instance Method Summary collapse
-
#initialize(api_token:, input:) ⇒ Post
constructor
A new instance of Post.
- #post ⇒ Object
Constructor Details
#initialize(api_token:, input:) ⇒ Post
Returns a new instance of Post.
7 8 9 10 |
# File 'lib/everhour2toggl/toggl/post.rb', line 7 def initialize(api_token:, input:) @api_token = api_token @input = input end |
Instance Method Details
#post ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/everhour2toggl/toggl/post.rb', line 12 def post uri = URI.parse("https://www.toggl.com/api/v8/time_entries") request = Net::HTTP::Post.new(uri) request.basic_auth(@api_token, "api_token") request.content_type = "application/json" = { use_ssl: uri.scheme == "https", } entries = JSON.parse(File.read(@input)) responses = Net::HTTP.start(uri.hostname, uri.port, ) do |http| entries.each do |entry| request.body = JSON.dump(entry) http.request(request) end end # puts responses end |