Class: Twitter2Mastodon::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter2mastodon/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Configuration

Returns a new instance of Configuration.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
# File 'lib/twitter2mastodon/configuration.rb', line 8

def initialize(config_file)
  file = File.expand_path(config_file)
  raise ArgumentError, "No file provided" unless File.exist?(file)

  configuration = YAML.load_file(file)
  @users = configuration["users"].map { |user| user.downcase }
  @twitter = configuration["twitter"]
  @mastodon = configuration["mastodon"]
end

Instance Attribute Details

#mastodonObject (readonly)

Returns the value of attribute mastodon.



6
7
8
# File 'lib/twitter2mastodon/configuration.rb', line 6

def mastodon
  @mastodon
end

#twitterObject (readonly)

Returns the value of attribute twitter.



6
7
8
# File 'lib/twitter2mastodon/configuration.rb', line 6

def twitter
  @twitter
end

#usersObject (readonly)

Returns the value of attribute users.



6
7
8
# File 'lib/twitter2mastodon/configuration.rb', line 6

def users
  @users
end

Instance Method Details

#mastodon_clientObject



27
28
29
# File 'lib/twitter2mastodon/configuration.rb', line 27

def mastodon_client
  Mastodon::REST::Client.new(base_url: mastodon["base_url"], bearer_token: mastodon["bearer_token"])
end

#twitter_clientObject



18
19
20
21
22
23
24
25
# File 'lib/twitter2mastodon/configuration.rb', line 18

def twitter_client
  Twitter::REST::Client.new do |config|
    config.consumer_key = twitter["consumer_key"]
    config.consumer_secret = twitter["consumer_secret"]
    config.access_token = twitter["access_token"]
    config.access_token_secret = twitter["access_token_secret"]
  end
end