// GetThreadSubscription checks to see if the authenticated user is subscribed
// to a thread.
//
// GitHub API docs: https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
764339
func (s *ActivityService) GetThreadSubscription(ctx context.Context, id string) (*Subscription, *Response, error) {
	u := fmt.Sprintf("notifications/threads/%v/subscription", id)

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	sub := new(Subscription)
	resp, err := s.client.Do(ctx, req, sub)
	if err != nil {
		return nil, resp, err
	}

	return sub, resp, nil
}
557695
func (c *Contributor) GetSubscriptionsURL() string {
	if c == nil || c.SubscriptionsURL == nil {
		return ""
	}
	return *c.SubscriptionsURL
}
1137200
func (p *provider) getUserTeams(token string) (sets.String, error) {
	userTeams := sets.NewString()
	err := p.page(p.githubUserTeamURL, token,
		func() interface{} {
			return &[]githubTeam{}
		},
		func(obj interface{}) error {
			for _, team := range *(obj.(*[]githubTeam)) {
				if len(team.Slug) > 0 && len(team.Organization.Login) > 0 {
					userTeams.Insert(strings.ToLower(team.Organization.Login + "/" + team.Slug))
				}
			}
			return nil
		},
	)
	return userTeams, err
}
673983
func (c Client) Get(id string, params *stripe.SubscriptionParams) (*stripe.Subscription, error) {
	path := stripe.FormatURLPath("/v1/subscriptions/%s", id)
	sub := &stripe.Subscription{}
	err := c.B.Call(http.MethodGet, path, c.Key, params, sub)
	return sub, err
}
622476
func (h *HubService) GetReadTokenWithAuth(repo string, auth Authenticator) (*TokenAuth, error) {
	path := fmt.Sprintf("repositories/%s/images", repo)
	req, err := h.newRequest("GET", path, auth)
	if err != nil {
		return nil, err
	}

	return h.do(req)
}
1104032
func newSubscription(provider *SubscriptionProvider) *Subscription {
	return &Subscription{
		id:       uuid.NewV4(),
		events:   make(chan interface{}, subscriptionChanSize),
		quitChan: make(chan struct{}),
		provider: provider,
	}
}
938158
func (u *User) GetSubscriptionsURL() string {
	if u == nil || u.SubscriptionsURL == nil {
		return ""
	}
	return *u.SubscriptionsURL
}
591899
func (m *SubscriptionManager) notifySubscriber(sub *newSubscription,
	block BlockNtfn) {

	select {
	case sub.ntfnQueue.ChanIn() <- block:
	case <-sub.quit:
	case <-m.quit:
		return
	}
}
110326
func (mc MongoClient) GetSubscriptionBySlug(slug string) (contract.Subscription, error) {
	return mc.getSubscription(bson.M{"slug": slug})
}
988216
func (m *SubscriptionManager) handleNewSubscription(sub *newSubscription) error {
	log.Infof("Registering block subscription: id=%d", sub.id)

	// We'll start by retrieving a backlog of notifications from the
	// client's best height.
	blocks, currentHeight, err := m.ntfnSource.NotificationsSinceHeight(
		sub.bestHeight,
	)
	if err != nil {
		return fmt.Errorf("unable to retrieve blocks since height=%d: "+
			"%v", sub.bestHeight, err)
	}

	// We'll then attempt to deliver these notifications.
	log.Debugf("Delivering backlog of block notifications: id=%d, "+
		"start_height=%d, end_height=%d", sub.id, sub.bestHeight,
		currentHeight)

	for _, block := range blocks {
		m.notifySubscriber(sub, block)
	}

	// With the notifications delivered, we can keep track of the new client
	// internally in order to deliver new block notifications about the
	// chain.
	m.subscribers[sub.id] = sub

	return nil
}
612662
func (n *Notifier) takeSubscription() *Subscription {
	n.mu.Lock()
	defer n.mu.Unlock()
	n.callReturned = true
	return n.sub
}
374758
func (d *Debugger) FindThread(id int) (*api.Thread, error) {
	d.processMutex.Lock()
	defer d.processMutex.Unlock()

	if _, err := d.target.Valid(); err != nil {
		return nil, err
	}

	for _, th := range d.target.ThreadList() {
		if th.ThreadID() == id {
			return api.ConvertThread(th), nil
		}
	}
	return nil, nil
}
968326
func (self *Notifications) Get(request *gottp.Request) {
	var args struct {
		Organization string `json:"org"`
		AppName      string `json:"app_name"`
		User         string `json:"user" required:"true"`
	}

	request.ConvertArguments(&args)
	paginator := request.GetPaginator()

	all, err := sentApi.GetAll(paginator, args.User, args.AppName, args.Organization)

	if err != nil {
		if err != mgo.ErrNotFound {
			log.Println(err)
			request.Raise(gottp.HttpError{
				http.StatusInternalServerError,
				"Unable to fetch data, Please try again later.",
			})

		} else {
			request.Raise(gottp.HttpError{
				http.StatusNotFound,
				"Not Found.",
			})
		}
		return
	}

	request.Write(all)
	return
}
861596
func (c Client) AddSubscription(s contract.Subscription) (string, error) {
	conn := c.Pool.Get()
	defer conn.Close()

	err := addSubscription(conn, &s)
	if err != nil {
		return "", err
	}

	return s.ID, nil
}
203870
func (r *Repository) GetSubscribersCount() int {
	if r == nil || r.SubscribersCount == nil {
		return 0
	}
	return *r.SubscribersCount
}
510394
func (c *PubSub) PSubscribe(patterns ...string) error {
	c.mu.Lock()
	defer c.mu.Unlock()

	err := c.subscribe("psubscribe", patterns...)
	if c.patterns == nil {
		c.patterns = make(map[string]struct{})
	}
	for _, s := range patterns {
		c.patterns[s] = struct{}{}
	}
	return err
}
1206731
func (r *Repository) GetSubscriptionURL() string {
	if r == nil || r.SubscriptionURL == nil {
		return ""
	}
	return *r.SubscriptionURL
}