Sha256: 97ea6af6815d38d258f1923c274516d90a9e90466ea1e8a1bacc4e7a771fbab8

Contents?: true

Size: 745 Bytes

Versions: 6

Compression:

Stored size: 745 Bytes

Contents

require 'rest'

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

    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 & 1 rubygems

Version Path
cocoapods-stats-1.0.0.beta.3 lib/cocoapods_stats/sender.rb
cocoapods-stats-1.0.0.beta.2 lib/cocoapods_stats/sender.rb
cocoapods-stats-1.0.0.beta.1 lib/cocoapods_stats/sender.rb
cocoapods-stats-0.6.2 lib/cocoapods_stats/sender.rb
cocoapods-stats-0.6.1 lib/cocoapods_stats/sender.rb
cocoapods-stats-0.6.0 lib/cocoapods_stats/sender.rb