Class: XapiScraper::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/xapi_scraper/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, retry_config: nil, timeout_ms: nil, bearer_auth: nil, security_source: nil, server: nil, server_url: nil, url_params: nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (StandardError)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/xapi_scraper/client.rb', line 57

def initialize(
  client: nil,
  retry_config: nil,
  timeout_ms: nil,
  bearer_auth: nil,
  security_source: nil,
  server: nil,
  server_url: nil,
  url_params: nil
)

  connection_options = {
    request: {
      params_encoder: Faraday::FlatParamsEncoder
    }
  }
  connection_options[:request][:timeout] = (timeout_ms.to_f / 1000) unless timeout_ms.nil?

  client ||= Faraday.new(**connection_options) do |f|
    f.request(:multipart, {flat_encode: true})
    # f.response :logger, nil, { headers: true, bodies: true, errors: true }
  end

  if !server_url.nil?
    if !url_params.nil?
      server_url = Utils.template_url(server_url, url_params)
    end
  end

  raise StandardError, "Invalid server \"#{server}\"" if !server.nil? && !SERVERS.key?(server)
  hooks = SDKHooks::Hooks.new
  @sdk_configuration = SDKConfiguration.new(
    client,
    hooks,
    retry_config,
    timeout_ms,
    bearer_auth,
    security_source,
    server_url,
    server
  )
  @sdk_configuration = hooks.sdk_init(config: @sdk_configuration)
  init_sdks
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def 
  @account
end

#analysisObject

Returns the value of attribute analysis.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def analysis
  @analysis
end

#articlesObject

Returns the value of attribute articles.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def articles
  @articles
end

#communitiesObject

Returns the value of attribute communities.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def communities
  @communities
end

#dmObject

Returns the value of attribute dm.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def dm
  @dm
end

#listsObject

Returns the value of attribute lists.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def lists
  @lists
end

#searchObject

Returns the value of attribute search.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def search
  @search
end

#timelinesObject

Returns the value of attribute timelines.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def timelines
  @timelines
end

Returns the value of attribute trending.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def trending
  @trending
end

#tweetsObject

Returns the value of attribute tweets.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def tweets
  @tweets
end

#usersObject

Returns the value of attribute users.



20
21
22
# File 'lib/xapi_scraper/client.rb', line 20

def users
  @users
end

Instance Method Details

#get_url(base_url:, url_variables: nil) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/xapi_scraper/client.rb', line 118

def get_url(base_url:, url_variables: nil)
  sd_base_url, sd_options = @sdk_configuration.get_server_details

  if base_url.nil?
    base_url = sd_base_url
  end

  if url_variables.nil?
    url_variables = sd_options
  end

  return Utils.template_url(base_url, url_variables)
end

#init_sdksObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/xapi_scraper/client.rb', line 103

def init_sdks
  @search = Search.new(@sdk_configuration)
  @tweets = Tweets.new(@sdk_configuration)
  @users = Users.new(@sdk_configuration)
  @analysis = Analysis.new(@sdk_configuration)
  @dm = Dm.new(@sdk_configuration)
  @articles = Articles.new(@sdk_configuration)
  @communities = Communities.new(@sdk_configuration)
  @lists = Lists.new(@sdk_configuration)
  @trending = Trending.new(@sdk_configuration)
  @timelines = Timelines.new(@sdk_configuration)
  @account = Account.new(@sdk_configuration)
end