croudia4r 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +87 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/croudia4r.gemspec +25 -0
- data/lib/croudia/client.rb +85 -0
- data/lib/croudia/error.rb +5 -0
- data/lib/croudia/object/base.rb +30 -0
- data/lib/croudia/object/cursor.rb +9 -0
- data/lib/croudia/object/entities.rb +10 -0
- data/lib/croudia/object/identity.rb +9 -0
- data/lib/croudia/object/ids.rb +9 -0
- data/lib/croudia/object/list.rb +10 -0
- data/lib/croudia/object/location.rb +9 -0
- data/lib/croudia/object/media.rb +9 -0
- data/lib/croudia/object/relationship.rb +11 -0
- data/lib/croudia/object/relationship_collection.rb +9 -0
- data/lib/croudia/object/relationship_user.rb +9 -0
- data/lib/croudia/object/search_metadata.rb +10 -0
- data/lib/croudia/object/search_result.rb +12 -0
- data/lib/croudia/object/secret_mail.rb +16 -0
- data/lib/croudia/object/source.rb +9 -0
- data/lib/croudia/object/status.rb +21 -0
- data/lib/croudia/object/tokens.rb +9 -0
- data/lib/croudia/object/trend.rb +14 -0
- data/lib/croudia/object/trend_details.rb +9 -0
- data/lib/croudia/object/user.rb +15 -0
- data/lib/croudia/rest/account.rb +57 -0
- data/lib/croudia/rest/blocks.rb +56 -0
- data/lib/croudia/rest/favorites.rb +47 -0
- data/lib/croudia/rest/followers.rb +36 -0
- data/lib/croudia/rest/friend_ships.rb +60 -0
- data/lib/croudia/rest/friends.rb +36 -0
- data/lib/croudia/rest/mutes/users.rb +58 -0
- data/lib/croudia/rest/mutes.rb +9 -0
- data/lib/croudia/rest/oauth.rb +48 -0
- data/lib/croudia/rest/search.rb +33 -0
- data/lib/croudia/rest/secret_mails.rb +96 -0
- data/lib/croudia/rest/statuses.rb +170 -0
- data/lib/croudia/rest/trends.rb +19 -0
- data/lib/croudia/rest/users.rb +33 -0
- data/lib/croudia/version.rb +3 -0
- data/lib/croudia.rb +2 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8915cc116dcf489e508d7131a723b0938f9f8b17
|
4
|
+
data.tar.gz: 2f8f0cc1ef1c271194f8c65152e635936c367108
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 56c985332a0a8ec5d4538363a32cbd071284a95179d1354e2067d325309b6b639b4c9a2a9df55388d946115705e66ebdb05898cc6533926be0a6627fab35a054
|
7
|
+
data.tar.gz: a5b6fe74278878223791173280c5acb753a2f698906db591928bec185fc6ee8f0cf0a210bc67da11a95b6aeaae9276cf0c53f1ae52c812eb2a0544557919fdcb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Croudia for Ruby
|
2
|
+
|
3
|
+
[Croudia](https://croudia.com) API wrapper gem.
|
4
|
+
You use as [twitter gem](https://github.com/sferik/twitter).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'croudia4r'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install croudia4r
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'croudia'
|
25
|
+
```
|
26
|
+
|
27
|
+
Configuring client...
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
client = Croudia::Client.new({client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET'})
|
31
|
+
```
|
32
|
+
|
33
|
+
and authorize.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
cleint.authorize_url
|
37
|
+
# => https://api.croudia.com/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID
|
38
|
+
|
39
|
+
token = client.token({code: 'AUTHORIZATION_CODE'})
|
40
|
+
client = Croudia::Client.new({client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET', access_token: token.access_token})
|
41
|
+
```
|
42
|
+
#### Authorization user profile.
|
43
|
+
```ruby
|
44
|
+
user = client.verify_credentials
|
45
|
+
user.screen_name
|
46
|
+
# => MikazukiFuyuno
|
47
|
+
```
|
48
|
+
|
49
|
+
#### Updating status.
|
50
|
+
```ruby
|
51
|
+
status = client.update_status(status: 'Hello, world')
|
52
|
+
status.text
|
53
|
+
# => Hello, world
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Get timeline.
|
57
|
+
##### public timeline
|
58
|
+
```ruby
|
59
|
+
client.public_timeline.each do |status|
|
60
|
+
puts status.text
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
##### mentions
|
65
|
+
```ruby
|
66
|
+
client.mentions_timeline.each do |status|
|
67
|
+
puts status.text
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
#### Follow user.
|
72
|
+
```ruby
|
73
|
+
client.follow(screen_name: 'MikazukiFuyuno')
|
74
|
+
client.follow(user_id: 43391)
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
## Development
|
79
|
+
|
80
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
81
|
+
|
82
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fuyuno/croudia4r.
|
87
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "croudia4r"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/croudia4r.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'croudia/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "croudia4r"
|
8
|
+
spec.version = Croudia::VERSION
|
9
|
+
spec.authors = ["Mikazuki Fuyuno"]
|
10
|
+
spec.email = ["mikazuki_fuyuno@outlook.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Croudia API wrapper gem.}
|
13
|
+
spec.description = %q{Croudia API wrapper gem.}
|
14
|
+
spec.homepage = "https://github.com/fuyuno/croudia4r"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "typhoeus"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require 'typhoeus'
|
4
|
+
|
5
|
+
require 'croudia/error'
|
6
|
+
require 'croudia/rest/account'
|
7
|
+
require 'croudia/rest/blocks'
|
8
|
+
require 'croudia/rest/favorites'
|
9
|
+
require 'croudia/rest/followers'
|
10
|
+
require 'croudia/rest/friend_ships'
|
11
|
+
require 'croudia/rest/friends'
|
12
|
+
require 'croudia/rest/mutes'
|
13
|
+
require 'croudia/rest/oauth'
|
14
|
+
require 'croudia/rest/search'
|
15
|
+
require 'croudia/rest/secret_mails'
|
16
|
+
require 'croudia/rest/statuses'
|
17
|
+
require 'croudia/rest/trends'
|
18
|
+
require 'croudia/rest/users'
|
19
|
+
|
20
|
+
module Croudia
|
21
|
+
class Client
|
22
|
+
|
23
|
+
include Croudia::Rest::Account
|
24
|
+
include Croudia::Rest::Blocks
|
25
|
+
include Croudia::Rest::Favorites
|
26
|
+
include Croudia::Rest::Followers
|
27
|
+
include Croudia::Rest::FriendShips
|
28
|
+
include Croudia::Rest::Friends
|
29
|
+
include Croudia::Rest::Mutes
|
30
|
+
include Croudia::Rest::OAuth
|
31
|
+
include Croudia::Rest::Search
|
32
|
+
include Croudia::Rest::SecretMails
|
33
|
+
include Croudia::Rest::Statuses
|
34
|
+
include Croudia::Rest::Trends
|
35
|
+
include Croudia::Rest::Users
|
36
|
+
|
37
|
+
# Initializes a new Client object
|
38
|
+
#
|
39
|
+
# @param options [Hash]
|
40
|
+
# @return [Croudia::Client]
|
41
|
+
def initialize(params = {})
|
42
|
+
params.each do |key, value|
|
43
|
+
instance_variable_set("@#{key}", value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Updates access token.
|
48
|
+
#
|
49
|
+
# @param access_token [String] Access token.
|
50
|
+
def update_access_token(access_token)
|
51
|
+
@access_token = access_token
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(endpoint, params = {})
|
55
|
+
request = Typhoeus::Request.new(
|
56
|
+
"https://api.croudia.com/#{endpoint}",
|
57
|
+
method: :get,
|
58
|
+
params: params,
|
59
|
+
headers: {Authorization: "Bearer #{@access_token}"}
|
60
|
+
)
|
61
|
+
request.run
|
62
|
+
response = request.response
|
63
|
+
|
64
|
+
if(response.code == "401")
|
65
|
+
|
66
|
+
end
|
67
|
+
JSON.parse(response.body)
|
68
|
+
end
|
69
|
+
|
70
|
+
def post(endpoint, params = {})
|
71
|
+
request = Typhoeus::Request.new(
|
72
|
+
"https://api.croudia.com/#{endpoint}",
|
73
|
+
method: :post,
|
74
|
+
body: params,
|
75
|
+
headers: {Authorization: "Bearer #{@access_token}"}
|
76
|
+
)
|
77
|
+
request.run
|
78
|
+
response = request.response
|
79
|
+
|
80
|
+
if(response.code == "401")
|
81
|
+
end
|
82
|
+
JSON.parse(response.body)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Croudia
|
2
|
+
module Object
|
3
|
+
class Base
|
4
|
+
attr_reader :attrs
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
@attrs = attrs || {}
|
8
|
+
@attrs.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def attr_reader_as_object(attribute, object)
|
15
|
+
define_method(attribute.to_s) do
|
16
|
+
Object.const_get(object.to_s).new(@attrs[attribute.to_s])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def attr_reader_as_array_object(attribute, object)
|
21
|
+
define_method(attribute.to_s) do
|
22
|
+
@attr[attribute.to_s].map do |obj|
|
23
|
+
Object.const_get(object.to_s).new(obj)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'croudia/object/base'
|
2
|
+
require 'croudia/object/search_metadata'
|
3
|
+
require 'croudia/object/status'
|
4
|
+
|
5
|
+
module Croudia
|
6
|
+
module Object
|
7
|
+
class SearchResult < Base
|
8
|
+
attr_reader_as_array_object :statuses, Status
|
9
|
+
attr_reader_as_object :search_meta, SearchMetadata
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'croudia/object/identity'
|
2
|
+
require 'croudia/object/entities'
|
3
|
+
require 'croudia/object/user'
|
4
|
+
|
5
|
+
module Croudia
|
6
|
+
module Object
|
7
|
+
class SecretMail < Identity
|
8
|
+
attr_reader :text, :recipient_id, :recipient_screen_name,
|
9
|
+
:sender_id, :sender_screen_name, :created_at
|
10
|
+
|
11
|
+
attr_reader_as_object :entities, Entities
|
12
|
+
attr_reader_as_object :recipient, User
|
13
|
+
attr_reader_as_object :sender, User
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'croudia/object/identity'
|
2
|
+
require 'croudia/object/entities'
|
3
|
+
require 'croudia/object/user'
|
4
|
+
require 'croudia/object/source'
|
5
|
+
|
6
|
+
module Croudia
|
7
|
+
module Object
|
8
|
+
class Status < Identity
|
9
|
+
attr_reader :text, :favorited, :favorites_count,
|
10
|
+
:spread, :spread_count, :in_reply_to_status_id,
|
11
|
+
:in_reply_to_status_id_str, :in_reply_to_user_id,
|
12
|
+
:in_reply_to_user_id_str, :created_at
|
13
|
+
|
14
|
+
attr_reader_as_object :entities, Entities
|
15
|
+
attr_reader_as_object :source, Source
|
16
|
+
attr_reader_as_object :user, User
|
17
|
+
attr_reader_as_object :spread_status, Status
|
18
|
+
attr_reader_as_object :quote_status, Status
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'croudia/object/base'
|
2
|
+
require 'croudia/object/location'
|
3
|
+
require 'croudia/object/trend_details'
|
4
|
+
|
5
|
+
module Croudia
|
6
|
+
module Object
|
7
|
+
class Trend < Base
|
8
|
+
attr_reader :as_of, :created_at, :trends
|
9
|
+
|
10
|
+
attr_reader_as_object :locations, Location
|
11
|
+
attr_reader_as_array_object :trends, TrendDetails
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'croudia/object/identity'
|
2
|
+
|
3
|
+
module Croudia
|
4
|
+
module Object
|
5
|
+
class User < Identity
|
6
|
+
attr_reader :name, :screen_name, :profile_image_url_https,
|
7
|
+
:cover_image_url_https, :created_at, :description, :favorites_count,
|
8
|
+
:follow_request_sent, :followers_count, :following, :friends_count,
|
9
|
+
:location, :statuses_count, :protected, :url
|
10
|
+
|
11
|
+
alias_method :cover, :cover_image_url_https
|
12
|
+
alias_method :icon, :profile_image_url_https
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'croudia/object/user'
|
2
|
+
|
3
|
+
module Croudia
|
4
|
+
module Rest
|
5
|
+
module Account
|
6
|
+
|
7
|
+
# Returns an HTTP 200 OK response code and a representation of the requesting user if
|
8
|
+
# authentication was successful; returns a 401 status code and an error message if not.
|
9
|
+
# Use this method to test if supplied user credentials are valid.
|
10
|
+
#
|
11
|
+
# @see https://developer.croudia.com/docs/35_account_verify_credentials
|
12
|
+
# @return [Croudia::Object::User] Authenticated user
|
13
|
+
def verify_credentials
|
14
|
+
response = get('account/verify_credentials.json')
|
15
|
+
Croudia::Object::User.new(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Updates the authenticating user’s profile image.
|
19
|
+
#
|
20
|
+
# @see https://developer.croudia.com/docs/36_account_update_profile_image
|
21
|
+
# @return [Croudia::Object::User] Authenticated user
|
22
|
+
# @param params [Hash] A customized options.
|
23
|
+
# @option params [File] :image Profile image
|
24
|
+
def update_profile_image(params = {})
|
25
|
+
response = post('account/update_profile_image.json', params)
|
26
|
+
Croudia::Object::User.new(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Updates the authenticating user's cover image.
|
30
|
+
#
|
31
|
+
# @see https://developer.croudia.com/docs/39_account_update_cover_image
|
32
|
+
# @return [Croudia::Object::User] Authenticated user
|
33
|
+
# @param params [Hash] A customized options.
|
34
|
+
# @option params [File] :image Cover image
|
35
|
+
def update_cover_image(params = {})
|
36
|
+
response = post('account/update_cover_image.json', params)
|
37
|
+
Croudia::Object::User.new(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Updates the authenticating user's profile.
|
41
|
+
#
|
42
|
+
# @see https://developer.croudia.com/docs/37_account_update_profile
|
43
|
+
# @return [Croudia::Object::User] Authenticated user
|
44
|
+
# @param params [Hash] A customized options.
|
45
|
+
# @option params [String] :name Name
|
46
|
+
# @option params [String] :url Homepage url
|
47
|
+
# @option params [String] :location Location
|
48
|
+
# @option params [String] :description Bio
|
49
|
+
# @option params [Integer] :timersec Whisper Timer's time (seconds).
|
50
|
+
# @option params [Boolean] :protected Whispers published to the world (true) or followers only (false).
|
51
|
+
def update_profile(params = {})
|
52
|
+
response = post('account/update_profile.json', params)
|
53
|
+
Croudia::Object::User.new(response)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'croudia/object/ids'
|
2
|
+
require 'croudia/object/list'
|
3
|
+
require 'croudia/object/user'
|
4
|
+
|
5
|
+
module Croudia
|
6
|
+
module Rest
|
7
|
+
module Blocks
|
8
|
+
|
9
|
+
# Blocks the specified user from following the authenticating user.
|
10
|
+
#
|
11
|
+
# @see https://developer.croudia.com/docs/120_blocks_create
|
12
|
+
# @return [Croudia::Object::User] Blocked user
|
13
|
+
# @param params [Hash] A customized options.
|
14
|
+
# @option params [String] :screen_name The screen name of the potentially blocked user.
|
15
|
+
# @option params [Integer] :user_id The ID of the potentially blocked user.
|
16
|
+
def block(params = {})
|
17
|
+
response = post('blocks/create.json', params)
|
18
|
+
Croudia::Object::User.new(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Un-blocks the user specified in the ID parameter for the authenticating user.
|
22
|
+
#
|
23
|
+
# @see https://developer.croudia.com/docs/121_blocks_destroy
|
24
|
+
# @return [Croudia::Object::User] Un-blocked user.
|
25
|
+
# @param params [Hash] A customized options.
|
26
|
+
# @option params [String] :screen The screen name of the potentially un-blocked user.
|
27
|
+
# @option params [Integer] :user_id The ID of the potentially un-blocked user.
|
28
|
+
def unblock(params = {})
|
29
|
+
response = post('blocks/destroy.json', params)
|
30
|
+
Croudia::Object::User.new(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a collection of user objects that the authenticating user is blocking.
|
34
|
+
#
|
35
|
+
# @see https://developer.croudia.com/docs/122_blocks_list
|
36
|
+
# @return [Croudia::Object::List] A collection of users that the authenticating user is blocking.
|
37
|
+
# @param params [Hash] A customized options.
|
38
|
+
# @option params [Integer] :cursor The page cursor of collection.
|
39
|
+
def blocks(params = {})
|
40
|
+
response = get('blocks/list.json', params)
|
41
|
+
Croudia::Object::List.new(response)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a collection of user ids that the authenticating user is blocking.
|
45
|
+
#
|
46
|
+
# @see https://developer.croudia.com/docs/123_blocks_ids
|
47
|
+
# @return [Croudia::Object::IDs] A collection of ids that the authenticating user is blocking.
|
48
|
+
# @param params [Hash] A customized options.
|
49
|
+
# @option params [Integer] :cursor The page cursor of collection.
|
50
|
+
def block_ids(params = {})
|
51
|
+
response = get('blocks/ids.json', params)
|
52
|
+
Croudia::Object::IDs.new(response)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|