Sha256: 4b3304b26aa5a6439e4b655049625bcdd670e4e24408c9ad748173cc86c1c4b0

Contents?: true

Size: 752 Bytes

Versions: 6

Compression:

Stored size: 752 Bytes

Contents

require 'rest'

module CocoaPodsStats
  class Sender
    API_URL = 'https://stats.cocoapods.org/api/v1/install'.freeze

    def send(targets, pod_try: false)
      body = {
        :targets => targets,
        :cocoapods_version => Pod::VERSION,
        :pod_try => pod_try,
      }
      headers = {
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
      }
      curl(API_URL, body, headers)
    end

    private

    def curl(url, json, headers)
      headers = headers.map { |k, v| ['-H', "#{k}: #{v}"] }.flatten
      command = ['curl', *headers, '-X', 'POST', '-d', json.to_json, '-m', '30', url]
      dev_null = '/dev/null'
      Process.spawn(*command, :out => dev_null, :err => dev_null)
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/cocoapods-stats-1.1.0/lib/cocoapods_stats/sender.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/cocoapods-stats-1.1.0/lib/cocoapods_stats/sender.rb
cocoapods-stats-1.1.0 lib/cocoapods_stats/sender.rb
cocoapods-stats-1.0.0 lib/cocoapods_stats/sender.rb
cocoapods-stats-1.0.0.rc.1 lib/cocoapods_stats/sender.rb
cocoapods-stats-1.0.0.beta.4 lib/cocoapods_stats/sender.rb