Skip to content

Commit

Permalink
Bump to 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Oct 22, 2016
1 parent 252af58 commit 6e40f2c
Show file tree
Hide file tree
Showing 20 changed files with 128 additions and 45 deletions.
15 changes: 15 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
engines:
rubocop:
enabled: true
duplication:
enabled: true
config:
languages:
- ruby

ratings:
paths:
- "**.rb"

exclude_paths:
- spec/**/*
43 changes: 43 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Metrics/BlockNesting:
Max: 2

Metrics/LineLength:
AllowURI: true
Enabled: false

Metrics/MethodLength:
CountComments: false
Max: 10

Metrics/ModuleLength:
Max: 100

Metrics/ParameterLists:
Max: 4
CountKeywordArgs: true

Style/AccessModifierIndentation:
EnforcedStyle: indent

Style/CollectionMethods:
Enabled: true
PreferredMethods:
find_all: 'select'

Style/Documentation:
Enabled: false

Style/DoubleNegation:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/SpaceInsideHashLiteralBraces:
EnforcedStyle: space

Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: 'comma'

Style/RegexpLiteral:
Enabled: false
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: ruby
cache: bundler

notifications:
email: false

rvm:
- 2.0.0
- 2.1
- 2.2
- ruby-head
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org"
source 'https://rubygems.org'

gem 'rake'
gem 'yard'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mastodon-api (0.0.1)
mastodon-api (0.9.1)
addressable (~> 2.4)
http (~> 2.0)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ Mastodon API Ruby Gem

A ruby interface for the [Mastodon](https://github.com/Gargron/mastodon) API.

## Installation

gem 'mastodon-api', require: 'mastodon'

## Documentation

[RubyDoc](http://www.rubydoc.info/gems/mastodon-api/Mastodon/REST/API)
All the documentation is available on [RubyDoc](http://www.rubydoc.info/gems/mastodon-api/Mastodon/REST/API).

## Usage

Assuming that you already have an access token for a user on a given Mastodon instance:

require 'mastodon-api'

client = Mastodon::REST::Client.new(base_url: 'https://mastodon.social', bearer_token: 'your_access_token')

If you need to get an access token, you must first ensure that you have the client ID and client secret for your app on the given Mastodon instance (you should save those for future calls):
Expand Down
23 changes: 23 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

require 'rubocop/rake_task'
RuboCop::RakeTask.new

require 'yard'
YARD::Rake::YardocTask.new

require 'yardstick/rake/measurement'
Yardstick::Rake::Measurement.new do |measurement|
measurement.output = 'measurement/report.txt'
end

require 'yardstick/rake/verify'
Yardstick::Rake::Verify.new do |verify|
verify.threshold = 59.0
end

task default: [:spec, :rubocop, :verify_measurements]
2 changes: 1 addition & 1 deletion lib/mastodon/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Error < StandardError
500 => Mastodon::Error::InternalServerError,
502 => Mastodon::Error::BadGateway,
503 => Mastodon::Error::ServiceUnavailable,
504 => Mastodon::Error::GatewayTimeout
504 => Mastodon::Error::GatewayTimeout,
}.freeze

class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def request_headers
{
user_agent: @client.user_agent,
accept: '*/*',
authorization: "Bearer #{@client.bearer_token}"
authorization: "Bearer #{@client.bearer_token}",
}
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/mastodon/relationship.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Mastodon
class Relationship < Mastodon::Base
# @!attribute [r] id
# @return [Integer] Account ID
# @!attribute [r] following?
# @return [Boolean]
# @!attribute [r] followed_by?
# @return [Boolean]
# @!attribute [r] blocking?
# @return [Boolean]
# @return [Integer] Account ID
# @!attribute [r] following?
# @return [Boolean]
# @!attribute [r] followed_by?
# @return [Boolean]
# @!attribute [r] blocking?
# @return [Boolean]

normal_attr_reader :id
predicate_attr_reader :following, :followed_by, :blocking
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/rest/accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def following(id)
# @param uri [String] The URI of the remote user, in the format of username@domain
# @return [Mastodon::Account]
def follow_by_uri(uri)
perform_request_with_object(:post, "/api/v1/follows", { uri: uri }, Mastodon::Account)
perform_request_with_object(:post, '/api/v1/follows', { uri: uri }, Mastodon::Account)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/rest/statuses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Statuses
# @param media_ids [Array<Integer>]
# @return [Mastodon::Status]
def create_status(text, in_reply_to_id = nil, media_ids = [])
perform_request_with_object(:post, "/api/v1/statuses", array_param(:media_ids, media_ids).merge({ status: text, in_reply_to_id: in_reply_to_id }), Mastodon::Status)
perform_request_with_object(:post, '/api/v1/statuses', array_param(:media_ids, media_ids).merge(status: text, in_reply_to_id: in_reply_to_id), Mastodon::Status)
end

# Retrieve status
Expand Down
6 changes: 3 additions & 3 deletions lib/mastodon/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module Version
module_function

def major
0
1
end

def minor
9
0
end

def patch
1
0
end

def pre
Expand Down
2 changes: 1 addition & 1 deletion spec/mastodon/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe '#user_agent' do
it 'returns the user agent string' do
expect(subject.user_agent).to match /MastodonRubyGem/
expect(subject.user_agent).to match(/MastodonRubyGem/)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/mastodon/rest/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe '#verify_credentials' do
before do
stub_request(:get, "https://mastodon.social/api/v1/accounts/verify_credentials").to_return(fixture('verify_credentials.json'))
stub_request(:get, 'https://mastodon.social/api/v1/accounts/verify_credentials').to_return(fixture('verify_credentials.json'))
end

it 'returns logged in user\'s account' do
Expand All @@ -19,7 +19,7 @@

describe '#account' do
before do
stub_request(:get, "https://mastodon.social/api/v1/accounts/1").to_return(fixture('account.json'))
stub_request(:get, 'https://mastodon.social/api/v1/accounts/1').to_return(fixture('account.json'))
end

it 'returns an account' do
Expand All @@ -31,7 +31,7 @@

describe '#followers' do
before do
stub_request(:get, "https://mastodon.social/api/v1/accounts/1/followers").to_return(fixture('followers.json'))
stub_request(:get, 'https://mastodon.social/api/v1/accounts/1/followers').to_return(fixture('followers.json'))
end

it 'returns a collection of accounts' do
Expand All @@ -43,7 +43,7 @@

describe '#following' do
before do
stub_request(:get, "https://mastodon.social/api/v1/accounts/1/following").to_return(fixture('following.json'))
stub_request(:get, 'https://mastodon.social/api/v1/accounts/1/following').to_return(fixture('following.json'))
end

it 'returns a collection of accounts' do
Expand Down
2 changes: 1 addition & 1 deletion spec/mastodon/rest/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe '#create_app' do
before do
stub_request(:post, "https://mastodon.social/api/v1/apps").to_return(fixture('create-app.json'))
stub_request(:post, 'https://mastodon.social/api/v1/apps').to_return(fixture('create-app.json'))
end

it 'returns an app' do
Expand Down
2 changes: 1 addition & 1 deletion spec/mastodon/rest/relationships_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe '#relationships' do
before do
stub_request(:get, "https://mastodon.social/api/v1/accounts/relationships?id%5B%5D=236&id%5B%5D=365").to_return(fixture('relationships.json'))
stub_request(:get, 'https://mastodon.social/api/v1/accounts/relationships?id%5B%5D=236&id%5B%5D=365').to_return(fixture('relationships.json'))
end

it 'returns a collection of relationships' do
Expand Down
28 changes: 14 additions & 14 deletions spec/mastodon/rest/statuses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,62 @@

describe '#create_status' do
it 'returns newly created status' do
stub_request(:post, "https://mastodon.social/api/v1/statuses").to_return(fixture('create-status-only-text.json'))
stub_request(:post, 'https://mastodon.social/api/v1/statuses').to_return(fixture('create-status-only-text.json'))
status = @client.create_status('Writing a ruby API lib for Mastodon')
expect(status).to be_a Mastodon::Status
expect(status.content).to match /Writing a ruby API lib for Mastodon/
expect(status.content).to match(/Writing a ruby API lib for Mastodon/)
end

it 'raises error when no text is given' do
stub_request(:post, "https://mastodon.social/api/v1/statuses").to_return(fixture('create-status-no-text.json'))
stub_request(:post, 'https://mastodon.social/api/v1/statuses').to_return(fixture('create-status-no-text.json'))
expect { @client.create_status('') }.to raise_error Mastodon::Error::UnprocessableEntity
end
end

describe '#status' do
before do
stub_request(:get, "https://mastodon.social/api/v1/statuses/35768").to_return(fixture('status.json'))
stub_request(:get, 'https://mastodon.social/api/v1/statuses/35768').to_return(fixture('status.json'))
end

it 'returns a status' do
status = @client.status(35768)
status = @client.status(35_768)
expect(status).to be_a Mastodon::Status
expect(status.content).to match /youtu\.be\/HBBwXAPNLr0/
expect(status.content).to match(/youtu\.be\/HBBwXAPNLr0/)
expect(status.account.username).to eq 'Gargron'
end
end

describe '#destroy_status' do
before do
stub_request(:delete, "https://mastodon.social/api/v1/statuses/35989").to_return(fixture('destroy-status.json'))
stub_request(:delete, 'https://mastodon.social/api/v1/statuses/35989').to_return(fixture('destroy-status.json'))
end

it 'returns nothing' do
expect(@client.destroy_status(35989)).to be true
expect(@client.destroy_status(35_989)).to be true
end
end

describe '#reblog' do
before do
stub_request(:post, "https://mastodon.social/api/v1/statuses/35768/reblog").to_return(fixture('reblog.json'))
stub_request(:post, 'https://mastodon.social/api/v1/statuses/35768/reblog').to_return(fixture('reblog.json'))
end

it 'returns a status that wraps around the reblogged status' do
status = @client.reblog(35768)
status = @client.reblog(35_768)
expect(status).to be_a Mastodon::Status
expect(status.reblog.id).to eq 35768
expect(status.reblog.id).to eq 35_768
end
end

describe '#unreblog' do
before do
stub_request(:post, "https://mastodon.social/api/v1/statuses/35768/unreblog").to_return(fixture('unreblog.json'))
stub_request(:post, 'https://mastodon.social/api/v1/statuses/35768/unreblog').to_return(fixture('unreblog.json'))
end

it 'returns the originally reblogged status' do
status = @client.unreblog(35768)
status = @client.unreblog(35_768)
expect(status).to be_a Mastodon::Status
expect(status.id).to eq 35768
expect(status.id).to eq 35_768
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/mastodon/rest/suggestions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe '#suggestions' do
before do
stub_request(:get, "https://mastodon.social/api/v1/accounts/suggestions").to_return(fixture('suggestions.json'))
stub_request(:get, 'https://mastodon.social/api/v1/accounts/suggestions').to_return(fixture('suggestions.json'))
end

it 'returns a collection of accounts' do
Expand Down
6 changes: 3 additions & 3 deletions spec/mastodon/rest/timelines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe '#home_timeline' do
before do
stub_request(:get, "https://mastodon.social/api/v1/statuses/home").to_return(fixture('home.json'))
stub_request(:get, 'https://mastodon.social/api/v1/statuses/home').to_return(fixture('home.json'))
end

it 'returns a collection of statuses' do
Expand All @@ -19,7 +19,7 @@

describe '#mentions_timeline' do
before do
stub_request(:get, "https://mastodon.social/api/v1/statuses/mentions").to_return(fixture('mentions.json'))
stub_request(:get, 'https://mastodon.social/api/v1/statuses/mentions').to_return(fixture('mentions.json'))
end

it 'returns a collection of statuses' do
Expand All @@ -31,7 +31,7 @@

describe '#public_timeline' do
before do
stub_request(:get, "https://mastodon.social/api/v1/statuses/public").to_return(fixture('public.json'))
stub_request(:get, 'https://mastodon.social/api/v1/statuses/public').to_return(fixture('public.json'))
end

it 'returns a collection of statuses' do
Expand Down

0 comments on commit 6e40f2c

Please sign in to comment.