dune-api 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +601 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -0
- data/README.md.backup +61 -0
- data/Rakefile +2 -0
- data/apiary.apib +1769 -0
- data/app/constraints/dune/api/api_constraint.rb +17 -0
- data/app/controllers/dune/api/base_controller.rb +68 -0
- data/app/controllers/dune/api/v1/channels/members_controller.rb +33 -0
- data/app/controllers/dune/api/v1/channels_controller.rb +73 -0
- data/app/controllers/dune/api/v1/investments_controller.rb +70 -0
- data/app/controllers/dune/api/v1/press_assets_controller.rb +38 -0
- data/app/controllers/dune/api/v1/projects_controller.rb +76 -0
- data/app/controllers/dune/api/v1/rewards_controller.rb +9 -0
- data/app/controllers/dune/api/v1/sessions_controller.rb +27 -0
- data/app/controllers/dune/api/v1/tags_controller.rb +37 -0
- data/app/controllers/dune/api/v1/users_controller.rb +26 -0
- data/app/models/dune/api/access_token.rb +24 -0
- data/app/models/dune/api/investment.rb +14 -0
- data/app/models/dune/api/project.rb +23 -0
- data/app/models/dune/api/user_concern.rb +11 -0
- data/app/serializers/channel_member_serializer.rb +7 -0
- data/app/serializers/channel_serializer.rb +34 -0
- data/app/serializers/dune/api/investment_serializer.rb +44 -0
- data/app/serializers/dune/api/project_serializer.rb +86 -0
- data/app/serializers/press_asset_serializer.rb +11 -0
- data/app/serializers/reward_serializer.rb +13 -0
- data/app/serializers/tag_serializer.rb +10 -0
- data/app/serializers/user_serializer.rb +46 -0
- data/bin/rails +8 -0
- data/config/initializers/mime_types.rb +1 -0
- data/config/routes.rb +42 -0
- data/db/migrate/20140624141405_create_dune_api_access_tokens.rb +11 -0
- data/dune-api.gemspec +28 -0
- data/lib/dune/api.rb +12 -0
- data/lib/dune/api/engine.rb +11 -0
- data/lib/dune/api/paginated_controller.rb +19 -0
- data/lib/dune/api/version.rb +5 -0
- data/spec/constraints/neighborly/api/api_constraint_spec.rb +50 -0
- data/spec/controllers/neighborly/api/v1/channels/members_controller_spec.rb +82 -0
- data/spec/controllers/neighborly/api/v1/channels_controller_spec.rb +188 -0
- data/spec/controllers/neighborly/api/v1/investments_controller_spec.rb +178 -0
- data/spec/controllers/neighborly/api/v1/press_assets_controller_spec.rb +129 -0
- data/spec/controllers/neighborly/api/v1/projects_controller_spec.rb +317 -0
- data/spec/controllers/neighborly/api/v1/rewards_controller_spec.rb +28 -0
- data/spec/controllers/neighborly/api/v1/sessions_controller_spec.rb +67 -0
- data/spec/controllers/neighborly/api/v1/tags_controller_spec.rb +143 -0
- data/spec/controllers/neighborly/api/v1/users_controller_spec.rb +43 -0
- data/spec/factories.rb +78 -0
- data/spec/fixtures/image.png +0 -0
- data/spec/models/neighborly/api/investment_spec.rb +33 -0
- data/spec/models/neighborly/api/user_concern_spec.rb +33 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/shared_examples.rb +96 -0
- metadata +219 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module Dune::Api
|
2
|
+
module V1
|
3
|
+
class UsersController < BaseController
|
4
|
+
include PaginatedController
|
5
|
+
|
6
|
+
before_action :require_admin!, only: :index
|
7
|
+
has_scope :pg_search, as: :query
|
8
|
+
|
9
|
+
def index
|
10
|
+
respond_with_pagination collection
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
respond_with User.find(params[:id])
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def collection
|
20
|
+
@collection ||= begin
|
21
|
+
apply_scopes(User).order('created_at desc').all
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Dune::Api
|
2
|
+
class AccessToken < ActiveRecord::Base
|
3
|
+
self.table_name = :api_access_tokens
|
4
|
+
|
5
|
+
default_scope { where(expired: false) }
|
6
|
+
belongs_to :user
|
7
|
+
|
8
|
+
before_create :generate_token
|
9
|
+
|
10
|
+
def expire!
|
11
|
+
self.expired = true
|
12
|
+
save
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def generate_token
|
18
|
+
self.code = loop do
|
19
|
+
random_token = SecureRandom.urlsafe_base64(50, false)
|
20
|
+
break random_token unless self.class.exists?(code: random_token)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Dune::Api
|
2
|
+
class Investment < ::Investment
|
3
|
+
scope :between_values, ->(start_at, ends_at) do
|
4
|
+
return all unless start_at.present? && ends_at.present?
|
5
|
+
where('value between ? and ?',
|
6
|
+
start_at.to_s.sub(',', '').to_f,
|
7
|
+
ends_at.to_s.sub(',', '').to_f)
|
8
|
+
end
|
9
|
+
|
10
|
+
scope :by_project_id, ->(project_id) do
|
11
|
+
where(project_id: project_id)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Dune::Api
|
2
|
+
ProjectPolicy = ::ProjectPolicy
|
3
|
+
ProjectPolicy::Scope = ::ProjectPolicy::Scope
|
4
|
+
|
5
|
+
class Project < ::Project
|
6
|
+
%i(created_at expires_at online_date).each do |name|
|
7
|
+
# class << self
|
8
|
+
# def between_created_at(starts_at, ends_at)
|
9
|
+
# between_dates(:created_at, starts_at, ends_at)
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
define_singleton_method("between_#{name}") do |starts_at, ends_at|
|
13
|
+
between_dates(name, starts_at, ends_at)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.between_dates(attribute, starts_at, ends_at)
|
20
|
+
where(attribute => [starts_at..ends_at])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ChannelSerializer < ActiveModel::Serializer
|
2
|
+
has_one :user
|
3
|
+
|
4
|
+
def url
|
5
|
+
dune.channel_url(object.id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def html_url
|
9
|
+
main_app.channels_profile_url(object, subdomain: object.permalink)
|
10
|
+
end
|
11
|
+
|
12
|
+
attributes :id,
|
13
|
+
:name,
|
14
|
+
:description,
|
15
|
+
:permalink,
|
16
|
+
:created_at,
|
17
|
+
:updated_at,
|
18
|
+
:image,
|
19
|
+
:video_embed_url,
|
20
|
+
:video_url,
|
21
|
+
:how_it_works,
|
22
|
+
:how_it_works_html,
|
23
|
+
:terms_url,
|
24
|
+
:state,
|
25
|
+
:user_id,
|
26
|
+
:accepts_projects,
|
27
|
+
:submit_your_project_text,
|
28
|
+
:submit_your_project_text_html,
|
29
|
+
:start_content,
|
30
|
+
:start_hero_image,
|
31
|
+
:success_content,
|
32
|
+
:url,
|
33
|
+
:html_url
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Dune::Api
|
2
|
+
class InvestmentSerializer < ActiveModel::Serializer
|
3
|
+
def rights
|
4
|
+
{
|
5
|
+
can_pendent: object.can_pendent?,
|
6
|
+
can_wait_confirmation: object.can_wait_confirmation?,
|
7
|
+
can_confirm: object.can_confirm?,
|
8
|
+
can_cancel: object.can_cancel?,
|
9
|
+
can_request_refund: object.can_request_refund?,
|
10
|
+
can_refund: object.can_refund?,
|
11
|
+
can_push_to_trash: object.can_push_to_trash?
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
attributes :id,
|
16
|
+
:project_id,
|
17
|
+
:user_id,
|
18
|
+
:reward_id,
|
19
|
+
:value,
|
20
|
+
:confirmed_at,
|
21
|
+
:created_at,
|
22
|
+
:anonymous,
|
23
|
+
:key,
|
24
|
+
:credits,
|
25
|
+
:payment_method,
|
26
|
+
:payment_token,
|
27
|
+
:payment_id,
|
28
|
+
:address_street,
|
29
|
+
:address_number,
|
30
|
+
:address_complement,
|
31
|
+
:address_neighborhood,
|
32
|
+
:address_zip_code,
|
33
|
+
:address_city,
|
34
|
+
:address_state,
|
35
|
+
:address_phone_number,
|
36
|
+
:payment_choice,
|
37
|
+
:payment_service_fee,
|
38
|
+
:state,
|
39
|
+
:short_note,
|
40
|
+
:payment_service_fee_paid_by_user,
|
41
|
+
:matching_id,
|
42
|
+
:rights
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Dune::Api
|
2
|
+
class ProjectSerializer < ActiveModel::Serializer
|
3
|
+
has_one :user
|
4
|
+
|
5
|
+
def created_at
|
6
|
+
object.created_at.to_datetime.utc.rfc3339
|
7
|
+
end
|
8
|
+
|
9
|
+
def expires_at
|
10
|
+
value = object.expires_at
|
11
|
+
if value
|
12
|
+
value.to_datetime.utc.rfc3339
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def online_date
|
17
|
+
value = object.online_date
|
18
|
+
if value
|
19
|
+
value.to_datetime.utc.rfc3339
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def channel_id
|
24
|
+
object.last_channel.try(:id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def rights
|
28
|
+
{
|
29
|
+
can_approve: object.can_approve?,
|
30
|
+
can_launch: object.can_launch?,
|
31
|
+
can_reject: object.can_reject?,
|
32
|
+
can_push_to_draft: object.can_push_to_draft?,
|
33
|
+
can_push_to_trash: object.can_push_to_trash?
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
dune_api.project_url(object.id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def html_url
|
42
|
+
main_app.project_url(object)
|
43
|
+
end
|
44
|
+
|
45
|
+
attributes :id,
|
46
|
+
:about,
|
47
|
+
:about_html,
|
48
|
+
:address_city,
|
49
|
+
:address_neighborhood,
|
50
|
+
:address_state,
|
51
|
+
:address_zip_code,
|
52
|
+
:budget,
|
53
|
+
:budget_html,
|
54
|
+
:campaign_type,
|
55
|
+
:category_id,
|
56
|
+
:created_at,
|
57
|
+
:expires_at,
|
58
|
+
:featured,
|
59
|
+
:goal,
|
60
|
+
:hash_tag,
|
61
|
+
:headline,
|
62
|
+
:hero_image,
|
63
|
+
:home_page,
|
64
|
+
:name,
|
65
|
+
:online_date,
|
66
|
+
:online_days,
|
67
|
+
:organization_type,
|
68
|
+
:permalink,
|
69
|
+
:pledged,
|
70
|
+
:recommended,
|
71
|
+
:short_url,
|
72
|
+
:site,
|
73
|
+
:state,
|
74
|
+
:street_address,
|
75
|
+
:terms,
|
76
|
+
:terms_html,
|
77
|
+
:uploaded_image,
|
78
|
+
:video_embed_url,
|
79
|
+
:video_thumbnail,
|
80
|
+
:video_url,
|
81
|
+
:channel_id,
|
82
|
+
:rights,
|
83
|
+
:url,
|
84
|
+
:html_url
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class UserSerializer < ActiveModel::Serializer
|
2
|
+
def created_at
|
3
|
+
object.created_at.to_datetime.utc.rfc3339
|
4
|
+
end
|
5
|
+
|
6
|
+
def name
|
7
|
+
object.display_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def image_url
|
11
|
+
object.display_image
|
12
|
+
end
|
13
|
+
|
14
|
+
def total_contributed
|
15
|
+
object.user_total ? object.user_total.sum : 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def url
|
19
|
+
dune_api.user_url(object.id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def html_url
|
23
|
+
main_app.user_url(object)
|
24
|
+
end
|
25
|
+
|
26
|
+
def manager
|
27
|
+
(object.admin? || object.channel.present? || object.channels.any?)
|
28
|
+
end
|
29
|
+
|
30
|
+
attributes :id,
|
31
|
+
:bio,
|
32
|
+
:created_at,
|
33
|
+
:email,
|
34
|
+
:facebook_url,
|
35
|
+
:linkedin_url,
|
36
|
+
:other_url,
|
37
|
+
:profile_type,
|
38
|
+
:twitter_url,
|
39
|
+
:name,
|
40
|
+
:image_url,
|
41
|
+
:total_contributed,
|
42
|
+
:admin,
|
43
|
+
:url,
|
44
|
+
:html_url,
|
45
|
+
:manager
|
46
|
+
end
|
data/bin/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/dune/api/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1 @@
|
|
1
|
+
Mime::Type.register "application/vnd.api+json", :json_api
|
data/config/routes.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Dune::Api::Engine.routes.draw do
|
2
|
+
scope module: :v1,
|
3
|
+
constraints: Dune::Api::ApiConstraint.new(revision: 1, default: true),
|
4
|
+
defaults: { format: :json } do
|
5
|
+
|
6
|
+
resources :projects do
|
7
|
+
member do
|
8
|
+
put :approve
|
9
|
+
put :launch
|
10
|
+
put :reject
|
11
|
+
put :push_to_draft
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
resources :investments, only: %i(index show update destroy) do
|
16
|
+
member do
|
17
|
+
put :confirm
|
18
|
+
put :pendent
|
19
|
+
put :refund
|
20
|
+
put :hide
|
21
|
+
put :cancel
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
resources :rewards, only: %i(show)
|
26
|
+
resources :tags
|
27
|
+
resources :press_assets
|
28
|
+
resources :users, only: %i(index show)
|
29
|
+
|
30
|
+
resources :channels do
|
31
|
+
resources :members, only: %i(index create destroy), controller: 'channels/members'
|
32
|
+
|
33
|
+
member do
|
34
|
+
put :push_to_draft
|
35
|
+
put :push_to_online
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
post 'sessions', to: 'sessions#create'
|
40
|
+
delete 'sessions', to: 'sessions#destroy'
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateDuneApiAccessTokens < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :api_access_tokens do |t|
|
4
|
+
t.string :code, null: false
|
5
|
+
t.boolean :expired, default: false, index: true, null: false
|
6
|
+
t.references :user, index: true, null: false
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/dune-api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dune/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dune-api'
|
8
|
+
spec.version = Dune::Api::VERSION
|
9
|
+
spec.authors = ['Pierre Legrand']
|
10
|
+
spec.email = ['legrand.work@gmail.com']
|
11
|
+
spec.summary = 'dune API'
|
12
|
+
spec.description = 'This is the implementation of Dune API from neighborly api'
|
13
|
+
spec.homepage = 'https://github.com/FromUte/dune-api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'has_scope'
|
22
|
+
spec.add_dependency 'kaminari'
|
23
|
+
spec.add_dependency 'pundit'
|
24
|
+
spec.add_dependency 'rails', '~> 4.0'
|
25
|
+
spec.add_dependency 'active_model_serializers', '~> 0.8.0'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
27
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.0.0'
|
28
|
+
end
|