<commit_before>
require 'rest-core'

RestCore::Twitter = RestCore::Builder.client(:data) do
  s = self.class # this is only for ruby 1.8!
  use s::Timeout       , 10

  use s::DefaultSite   , 'https://api.twitter.com/'
  use s::DefaultHeaders, {'Accept' => 'application/json'}

  use s::Oauth1Header  ,
    'oauth/request_token', 'oauth/access_token', 'oauth/authorize'

  use s::CommonLogger  , method(:puts)

  use s::Cache         , {}, 3600 do
    use s::ErrorHandler  , lambda{ |env|
      if (body = env[s::RESPONSE_BODY]).kind_of?(Hash)
        raise body['error']
      else
        raise body
      end
    }
    use s::ErrorDetectorHttp
    use s::JsonDecode    , true
    run s::Ask
  end

  use s::Defaults      , :data     => lambda{{}}

  run s::RestClient
end

module RestCore::Twitter::Client
  include RestCore

  def oauth_token
    data['oauth_token'] if data.kind_of?(Hash)
  end
  def oauth_token= token
    data['oauth_token'] = token if data.kind_of?(Hash)
  end
  def oauth_token_secret
    data['oauth_token_secret'] if data.kind_of?(Hash)
  end
  def oauth_token_secret= secret
    data['oauth_token_secret'] = secret if data.kind_of?(Hash)
  end

  def tweet status, media=nil, opts={}
    if media
      post('https://upload.twitter.com/1/statuses/update_with_media.json',
        {:status => status, 'media[]' => media},
        {}, opts)
    else
      post('1/statuses/update.json', {:status => status}, opts)
    end
  end

  def statuses user, queries={}, opts={}
    get('1/statuses/user_timeline.json', {:id => user}.merge(queries), opts)
  end

  private
  def set_token query
    self.data = query
  end
end

RestCore::Twitter.send(:include, RestCore::ClientOauth1)
RestCore::Twitter.send(:include, RestCore::Twitter::Client)<commit_msg>twitter.rb: fix arguments for Twitter#tweet<commit_after>
require 'rest-core'

RestCore::Twitter = RestCore::Builder.client(:data) do
  s = self.class # this is only for ruby 1.8!
  use s::Timeout       , 10

  use s::DefaultSite   , 'https://api.twitter.com/'
  use s::DefaultHeaders, {'Accept' => 'application/json'}

  use s::Oauth1Header  ,
    'oauth/request_token', 'oauth/access_token', 'oauth/authorize'

  use s::CommonLogger  , method(:puts)

  use s::Cache         , {}, 3600 do
    use s::ErrorHandler  , lambda{ |env|
      if (body = env[s::RESPONSE_BODY]).kind_of?(Hash)
        raise body['error']
      else
        raise body
      end
    }
    use s::ErrorDetectorHttp
    use s::JsonDecode    , true
    run s::Ask
  end

  use s::Defaults      , :data     => lambda{{}}

  run s::RestClient
end

module RestCore::Twitter::Client
  include RestCore

  def oauth_token
    data['oauth_token'] if data.kind_of?(Hash)
  end
  def oauth_token= token
    data['oauth_token'] = token if data.kind_of?(Hash)
  end
  def oauth_token_secret
    data['oauth_token_secret'] if data.kind_of?(Hash)
  end
  def oauth_token_secret= secret
    data['oauth_token_secret'] = secret if data.kind_of?(Hash)
  end

  def tweet status, media=nil, opts={}
    if media
      post('https://upload.twitter.com/1/statuses/update_with_media.json',
        {:status => status, 'media[]' => media},
        {}, opts)
    else
      post('1/statuses/update.json', {:status => status}, {}, opts)
    end
  end

  def statuses user, queries={}, opts={}
    get('1/statuses/user_timeline.json', {:id => user}.merge(queries), opts)
  end

  private
  def set_token query
    self.data = query
  end
end

RestCore::Twitter.send(:include, RestCore::ClientOauth1)
RestCore::Twitter.send(:include, RestCore::Twitter::Client)
{'fraction_non_alphanumeric': 0.14126186487995535, 'fraction_numerical': 0.0072585147962032385, 'mean_word_length': 3.280764635603345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1662287', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1220, 'n_words': 279}